single.php页面,显示该分类的其他文章列表;

额...我可能没表达清楚.
就是single.php页面,显示该分类的其他文章列表;
请问如何实现?

共有6个回答 按发表时间排序
  • 1
    最佳答案
    知更鸟 - 2011-08-08
    <?php
    if ( is_single() ) :
    global $post;
    $categories = get_the_category();
    foreach ($categories as $category) :
        ?>
        <li class="widget widget_recent_entries" id="<?php $category->term_id;?>-posts">
            <h2 class="widgettitle"><?php echo $category->name; ?></h2>
            <ul>
            <?php
            $posts = get_posts('numberposts=5&category='. $category->term_id);
            foreach($posts as $post) :
            ?>
                <li>
                <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                </li>
            <?php endforeach; ?>
            </ul>
        </li>
    <?php
    endforeach; endif ; ?>
    <?php
    /*
    end show current category articles
    */
    ?>
    

    原文:http://www.juyimeng.com/how-to-show-current-category-articles-in-single-page.html

    xysemies - 2011-08-09

    谢谢酋长,看到我能回答的问题了,我也积极回答,(^__^) 嘻嘻……

  • 0
    摄氏度 - 2011-08-08

    显示同分类下的最新文章,内容摘自:http://faq.wopus.org/question/290/

    <?php
        if(is_category() || is_single()){
            if(is_category()){
                global $cat;
                $cats = get_categories(array(
                    'child_of' => $cat,
                   ));
              }else if(is_single()){
                $cats = get_the_category();
            }
               foreach($cats as $cat){
                $posts = get_posts(array(
                    'category' => $cat->cat_ID,
                       'exclude' => $post->ID,
                 ));
                   echo '
                   <ul class="related_post">';
                       foreach($posts as $post){
                        echo '<li><a href="'.get_permalink($post->ID).'">'.$post->post_title.'</a></li>';
                       }
                   echo '
                   </ul>';
               }
        }
    ?>
    
  • 0
    缝隙 - 2011-08-22
    同分类文章
      term_id); foreach($posts as $post) : ?>
    • ">
    缝隙 - 2011-08-22
    <div class="sidebar">
    <h2><strong>同分类文章</strong></h2>
    <ul>
    <?php $categories = get_the_category(); foreach ($categories as $category) : ?>
    <?php $posts = get_posts('numberposts=10&category='. $category->term_id); foreach($posts as $post) : ?>
        <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> <?php endforeach; ?>
    </ul>
         </div>
    
  • 0
    kc75228792 - 2013-01-17

    可是可以调用,但是用了这代码,文章下面的评论,也在同分类里随机调用,怎么会这样。求高手解决!!!

做好事要留名,请先登录再回答,如果还没有帐户请先注册