简体   繁体   English

WordPress:将自定义字段与页面标题匹配并显示相关文章

[英]Wordpress: Match custom field to page title and display related posts

I have a custom field named article_author. 我有一个名为article_author的自定义字段。 It is used to display the name of the author. 它用于显示作者的姓名。 Many different users upload articles on behalf of the authors. 许多不同的用户代表作者上传文章。

All authors have a page with their details, bio etc on it. 所有作者的页面上都有其详细信息,个人简介等。

I would like to display the latest 5 posts by the author on their bio page by matching the page title to the custom field. 我想通过将页面标题与自定义字段匹配来显示作者的最新5个帖子。

I have no idea how to go about doing this, I have searched the web for weeks but still no luck. 我不知道该怎么做,我已经在网上搜索了数周,但仍然没有运气。 I am new to php and wordpress. 我是php和wordpress的新手。

Would appreciate any help you guys can offer. 希望您能提供任何帮助。

Many thanks 非常感谢

How did you set up the bio pages? 您如何设置个人简介页? Are they using author.php ? 他们在使用author.php吗? Have you added the authors to the site as users? 您是否已以用户身份将作者添加到站点?

If so you can assign the posts the author has written to their user, this way when the author.php template is loaded, the loop will already contain their latest 5 posts. 如果是这样,您可以将作者已写的帖子分配给他们的用户,这样,当加载author.php模板时,循环将包含其最新的5帖子。

Eg, if you have a user called 'Steve' and assign two posts to him, when visiting http://www.yourwebsite.com/author/steve/ - this will load up the author.php file from your theme 例如,如果您有一个名为“ Steve”的用户,并在访问http://www.yourwebsite.com/author/steve/时为其分配了两个帖子,这将从您的主题中加载author.php文件

More details on Author Templates here: http://codex.wordpress.org/Author_Templates 有关作者模板的更多详细信息,请参见: http : //codex.wordpress.org/Author_Templates

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM