您的位置:首页 > 其它

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

2013-11-19 17:29 351 查看
<ul>

    <?php

    $post_num = 10; 

    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>

上面的数字是调用文章多少篇,现在代码上的显示10篇
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  WordPress 相关文章