【发布时间】:2015-10-28 08:06:35
【问题描述】:
我正在使用 wordpress 主题,我想根据类别在不同页面上显示帖子。
例如页面名称是“博客”,帖子类别是 postBlog,你能告诉我如何根据类别使用帖子。
谢谢
【问题讨论】:
-
请检查我的答案。
我正在使用 wordpress 主题,我想根据类别在不同页面上显示帖子。
例如页面名称是“博客”,帖子类别是 postBlog,你能告诉我如何根据类别使用帖子。
谢谢
【问题讨论】:
你想做什么可以用WordPress Category Template来实现。
来自法典:
For instance, when a viewer clicks on a link to one of the Categories on your site, he or she is taken to a page listing the Posts from that particular Category in chronological order, from newest Posts at the top to oldest at the bottom.
您可以在您的主题中创建一个名为:category.php 的文件,在其中放入一个 loop,然后 WordPress 会自动为您执行此操作。
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
然后用页面满足您的需求。您可以查看The Loop here in this link 的文档。
【讨论】:
在您的主题目录中创建一个模板category-catname.php 或category-catID.php。
【讨论】:
我认为人们在尝试使用页面时会感到困惑,而实际上他们最好使用类别。如果您想让博客文章出现在不同的 URL 或“页面”上,那么您所要做的就是设置您的类别并将这些类别放入您的菜单中。然后,当您发布时,请确保选择您希望该帖子显示的类别。您根本不必使用页面。页面更适合静态内容。
祝你好运,我希望这会有所帮助。
【讨论】: