wordpress通过TAG关键词调用相关文章

需要提前建立一个tag页,再通过地址来判断当前tag值。

wordpress通过TAG关键词调用相关文章

<ul>
    <?php
    $post_num = 8; 
    global $post;
    $tmp_post = $post;
    $tags = ''; $i = 0;
    if ( get_the_tags( $post->ID ) ) {
    foreach ( get_the_tags( $post->ID ) as $tag ) $tags .= $tag->name . ',';
    $tags = strtr(rtrim($tags, ','), ' ', '-');
    $myposts = get_posts('numberposts='.$post_num.'&tag='.$tags.'&exclude='.$post->ID);
    foreach($myposts as $post) {
    setup_postdata($post);
    ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php
    }
    }
    $post = $tmp_post; setup_postdata($post);
    ?>
</ul>

11
蜗牛不带伞
蜗牛不带伞
发表于2018-07-16 3:03
标签 tagtag文章wordpress调用文章 归档于 wordpress