动态图像链接取决于摘录/“单个帖子”在 WordPress 中查看
我正在开发一个新的 WordPress 主题;默认索引视图显示最近帖子的摘录。有些帖子将涉及文件下载,并包含图像、描述以及指向所描述文件的托管位置的链接。这些类型的帖子的图像将通过链接进行锚定(其他类型的帖子可能包含未链接的图像)。
对于这些类型的帖子,我希望图像在摘录中显示时链接到其条目的完整帖子视图(single.php),但对于相同的图像在作为完整帖子视图的一部分显示时链接到外部下载链接。
我不确定我到底如何实现这一点。 任何帮助将不胜感激!
I'm working on a new Wordpress theme; the default index view displays the excerpts of recent posts. Some posts will be regarding file downloads, and include an image, description, and link to the location where the described files are hosted. The images for these types of posts will be anchored with links(other types of posts may contain images that are not linked).
For these types of posts, I would like the images to link to their entry's full post views(single.php) when displayed in excerpts, but for the same images to link to an external download link when displayed as part of the full post view.
I'm not sure how exactly I would accomplish that.
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为我没有定义帖子缩略图,并且由于帖子可能包含也可能不包含多个图像,所以我最终这样做了:
我关闭了摘录中的标签(我有一个摘录插件启用了摘录中的标签),然后我添加了将以下内容添加到 function.php 文件中:
然后,我将以下内容添加到帖子标题和摘录/内容之间的主索引模板文件中:
,它被包裹在 a 中
随机注释:由于样式原因
。再次感谢您引导我走向正确的方向。
Because I don't have post thumbnails defined, and since posts may or may not contain multiple images, I ended up doing it this way:
I turned off tags in excerpts(I had an excerpt plugin enabling tags in excerpt), then I added the following to the function.php file:
Then I added the following to the main index template file in between the posts title and the excerpt/content:
Random note: It's wrapped in a
for styling reasons.
Thanx again for guiding me in the right direction.
如果您的主题在首页使用“the_excerpt()”,我认为您可以在functions.php中添加一个过滤器,并使用正则表达式将链接href从下载链接更改为永久链接。
就像,
如果不知道您的下载链接是什么样子,我就无法创建实际的正则表达式
if your theme uses 'the_excerpt()' for the front page, I think you can add a filter in functions.php, and with a regexp change the link href from the download link to the permalink.
something like,
I can't create an actual regular expression without knowing what your download link looks like