WordPress 中每篇文章中的图片
如果您访问此网站,您将看到每个帖子都有一个图像和摘要。实施该方法的正确方法是什么?
这是使用 WordPress 自定义字段完成的吗?或者这是否编码在主题文件夹中的 image.php 文件中?我该怎么做?
If you visit this site, you will see that there is an image and summary for each post. What is the proper way to implement that?
Is this done using WordPress custom fields? Or whether this is coded in image.php file present in theme folder? How do I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
有一个更好的方法 - 你也可以使用这个函数 -
如果你将此函数插入到你的主题的functions.php中,你可以插入到
你的single.php和index.php中
这个函数将捕获有史以来帖子中的第一个图像并如果没有人可用,它将显示它 - 它将使用一个您可以更改的默认图像...
或者另一种方式:
如果您将其放入您的index.php或single.php中,它将使用字段“postimage”中给出的图像“(帖子/页面中的自定义字段)。
There is a better way - you can also use this function too -
if you insert this function to your functions.php of your theme you can insert
in your single.php and index.php
This function will catch the first image in ever post and will display it, if no one is available - it will use one Default image which you can change...
Or another way:
If you put this in your index.php or single.php it will use the image given in field "postimage" (customfield in posts/pages).
最有可能的是采用图像源的自定义字段。然后,将更改帖子模板以查看是否设置了图像,如果设置了,则将其包含在内。
Most likely by a custom field which takes an image source. Then the post template would be changed to see if an image is set and, if it is, include it.
为通过 Google 找到此内容的人添加额外的答案,因为原始答案意味着需要进行大量手动编码。
catswhocode 博客不再像描述的那样,因此此建议可能不完全适合,但我认为值得一提的是,WordPress 现在明确支持“发布缩略图”。有关更多信息,请参阅此处: http://codex.wordpress.org/Post_Thumbnails
仅针对文章作为首页上的摘要,实现此目的的一种方法是将对
the_content(~~~)
的调用(例如在 content.php 中)替换为对the_excerpt()
的调用代码>.有关摘录的更多信息,请参阅 http://codex.wordpress.org/ExcerptAdding an additional answer for people who find this via Google, as the original answers imply that a lot of hand-coding is needed.
The catswhocode blog no longer looks like described, so this advice may not fit exactly, but I thought it worth mentioning that WordPress now supports "Post Thumbnails" explicitly. For more information, see here: http://codex.wordpress.org/Post_Thumbnails
As for the article only being a summary on the front page, one way to achieve this is by replacing a call to
the_content(~~~)
(e.g. in content.php) with one tothe_excerpt()
. For more on excerpts, see http://codex.wordpress.org/Excerpt