简体   繁体   English

显示特定类别的帖子

[英]Display posts from specific category

I am completely new in Wordpress, please forgive me for my stupid question. 我是Wordpress的新手,请原谅我的愚蠢问题。 I want to create menu with all categories. 我想创建所有类别的菜单。 I created such menu but after clicking on specific menu item with category name it links me to my home page. 我创建了这样的菜单,但是在单击具有类别名称的特定菜单项后,它会将我链接到我的主页。 What code should i add to my page to display all posts with specific category? 我应该在页面上添加什么代码以显示具有特定类别的所有帖子?

Inside your wordpress theme you must have a page called "content.php" Which will get included through the code below. 在您的wordpress主题内,您必须有一个名为“ content.php”的页面,该页面将通过下面的代码包含在内。 In that template you can huse the wordpress functions like so... the_title(); 在该模板中,您可以像这样使用wordpress函数... the_title(); And so on.. You will just have to check the Wordpress Codex 依此类推..您只需要检查Wordpress Codex

$args['tax_query'][] =
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'category slug must go here'
);

<?php $query = new WP_Query($args); ?>
<?php while ( $query->have_posts() ) : the_post(); ?>
 <div>
   <?php 
     $query->the_post();        
     get_template_part( 'content', get_post_format() ); 
   ?>
</div>
<?php endwhile; ?>

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

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