简体   繁体   English

WordPress的显示帖子标签和类别

[英]Wordpress Display Post Tags and by Category

Following is my wordpress query which I am using to display all the posts but the query is not displaying the post's tags, Also kindly let me know how to modify the following query so it displays the posts from any specific category. 以下是我用来显示所有帖子的wordpress查询,但是该查询未显示帖子的标签,也请让我知道如何修改以下查询,以便它显示任何特定类别的帖子。

<?php 
  $wp_query2 = null; 
  $wp_query2 =  new WP_Query(array(

 'post_type' => 'post',

 'post_status' => 'publish',
 'caller_get_posts'=> 0  ));

  while ($wp_query2->have_posts()) : $wp_query2->the_post(); 
?>

        <?php the_date(); ?>
        <br />
        <?php the_title(); ?>   
        <?php the_content(); ?>

<?php endwhile; ?>


<?php 
  wp_reset_query();
?>

You may try this 你可以试试这个

$args = array(
    'post_type' => 'post',
    'tax_query' => array(
        'relation' => 'OR',
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => array( 'category1', 'category2' ) // replace these
            ),
            array(
                'taxonomy' => 'post_tag',
                    'field' => 'slug',
                    'terms' => array( 'tag1, tag2' ) // replace these
            )
    )
);

$query = new WP_Query( $args );
while ($query->have_posts()) : $query->the_post();
    // ...
    the_content();
    the_tags(); // display tags
endwhile;

Check WP Query and the_tags . 检查WP Querythe_tags

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

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