0

我正在寻找创建一个 tag.php 页面,当用户单击标签云中的标签时,它会显示所有标签。这是我到目前为止所得到的,但这似乎显示了我所有的帖子。

<article class="articles"> 
<?php
echo '<h2>Tag:';
$tag = single_tag_title();
echo '</h2>';
$args = array(
            'taxonomy' => $tag,
            'terms' => $tag,
);
$postslist = get_posts( $args );?>

<?php foreach( $postslist as $post ) :  setup_postdata($post); ?>


      <div class="clear"></div>
      <span class="timestamp"><?php echo mysql2date('j M Y', $post->post_date) ;?></span></h2>
      <p class="about"><?php the_title(); ?></p>
      <?php the_content(''); ?>
      <?php endforeach;?>
</div>

我似乎无法弄清楚这一点,我一直在谷歌搜索,但我似乎无法找到我想要的信息......

4

2 回答 2

0

single_tag_title的它没有返回变量:

$tag = single_tag_title('', false);

尝试:

<?php
$tag = single_tag_title('', false);
echo '<h2>Tag: '.$tag.'</h2>';

$args = array(
            'taxonomy' => $tag,
            'terms' => $tag,
);
$postslist = get_posts( $args );?>

<?php foreach( $postslist as $post ) :  setup_postdata($post); ?>
<div class="clear"></div>
      <span class="timestamp"><?php echo mysql2date('j M Y', $post->post_date) ;?></span></h2>
      <p class="about"><?php the_title(); ?></p>
      <?php the_content(); ?>
</div>
<?php endforeach;?>
于 2012-09-18T21:20:43.940 回答
0

尝试使用 wp_query

$tag = single_tag_title('', false);
echo '<h2>Tag: '.$tag.'</h2>';

// The Query
$the_query = new WP_Query( $tag );

// The Loop
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
            $the_query->the_post();
    $post = get_queried_object();
            echo "<div class='clear'></div>
  <span class='timestamp'>" . mysql2date('j M Y', $post->post_date) . " </span></h2>
  <p class='about'" . the_title() . "</p>";
  <?php the_content(); ?>
</div>
}
} else {
// no posts found
}
/* Restore original Post Data */
wp_reset_postdata();

请注意,我没有测试过这段代码!

于 2013-11-05T20:38:17.953 回答