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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀