duanjianshen4871 2014-12-23 05: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-23 05:33
    关注

    use include argument in your get categories function

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

报告相同问题?

悬赏问题

  • ¥15 MATLAB联合adams仿真卡死如何解决(代码模型无问题)
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline
  • ¥50 分布式追踪trace异常问题
  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function