duanjianshen4871 2014-12-22 21:29 采纳率: 100%
浏览 24
已采纳

Wordpress - 从显示所有类别到显示特定

Currently, I have a page that shows posts from all categories (3 categories). Now, I'm trying to make a similar page but I don't want to show one of those categories.

I know that I need it to go from Show all to show categories with id 10,11,15.

Here's my current working php script that shows all.

<div class="clearFloat">
<div id="container">
    <div id="content" role="main">
        <?php
        // get all the categories from the database
        $cats = get_categories();

        // loop through the categries
        foreach ($cats as $cat) :
            // setup the cateogory ID
            $cat_id= $cat->term_id;
            // Make a header for the cateogry
            ?>
            <div class='category-container clearFloat'>
                <h2><?php echo $cat->name; ?></h2>
                <?php
            // create a custom wordpress query
            query_posts("cat=$cat_id&posts_per_page=100");
            // start the wordpress loop!
            if (have_posts()) : while (have_posts()) : the_post(); ?>
                <?php // create our link now that the post is setup ?>
                <div class="course">
                    <a href="<?php echo get_the_permalink(); ?>">
                        <h3 class="course-title"><?php the_title(); ?></h3>
                    </a>
                    <div class="promo"></div>
                    <div class="course-content">
                        <?php the_excerpt(); ?>
                    </div>
                    <div class="fadeUp"></div>
                    <a class="more-link" href="<?php echo get_the_permalink(); ?>">Find out more</a>
                </div>
            <?php endwhile; endif; // done our wordpress loop. Will start again for each category ?>
            </div>
        <?php endforeach; wp_reset_query();// done the foreach statement ?>

    </div><!-- #content -->
</div><!-- #container -->

展开全部

  • 写回答

2条回答 默认 最新

  • dousao2186 2014-12-22 21:33
    关注

    use include argument in your get categories function

    $args = array('include'=>'10,11,15');
    $cats = get_categories($args);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部