按类别显示除选定帖子以外的所有帖子

时间:2016-06-04 05:24:18

标签: wordpress

我已经显示了“主页”类别帖子主页。点击“Readmore”第一篇文章。 它显示了第一篇文章的所有细节。

现在我想用“Readmore”显示“first post”下面的所有帖子。

这是我的代码,它显示了一些其他类别的帖子。

<?php
  $categories = get_the_category();
  $catID = the_category_ID($echo=false); //Current selected category ID
  $catPost = get_posts('cat=$catID&posts_per_page=3');
  foreach ($catPost as $post) : setup_postdata($post);
?>
  <h1><a><?php the_title(); ?></a></h1>
  <?php the_excerpt(); ?> 
  <p class="postinfo">Written by: <?php the_author_posts_link(); ?>
  Posted on: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>
  Categories: <?php the_category(', '); ?></p>
  <hr />
<?php  endforeach;?>

enter image description here

帖子页面

enter image description here

1 个答案:

答案 0 :(得分:2)

试试这种方式..

<?php
    global $post;
    if(is_category() || is_single()){
    foreach(get_the_category() as $category)
    {
    $current = $category->cat_ID;
    $current_name = $category->cat_name;

    //query_posts("cat=". $current);

    $myposts = get_posts(array('category__in' => array($current)));

    //$myposts = get_posts('numberposts=50&category='.$current); 

    //query_posts(array('category__in' => array(11)));
        }
    }

    foreach($myposts as $post) :
    setup_postdata($post); 

    ?>
    <li>
    <a href="<?php the_permalink(); ?>">
    <?php the_title(); ?></a>
    </li>

    <?php endforeach; ?>