dsd57259 2013-02-22 05:18
浏览 40
已采纳

只在wordpress循环中显示特定类别?

How Can I only show a specific category in my wordpress index page? Below is my theme code...

Also, when looking at the URL for my category (how I usually get the ID) it seems a strange format..

http://oil.wpengine.com/wp-admin/edit-tags.php?action=edit&taxonomy=category&tag_ID=1179&post_type=post

<?php query_posts( array ( 'Event_News' => 'event-news' ) ); ?>
    <?php if (have_posts()) : ?>

    <ul class="posts">
        <li id="post-<?php the_ID(); ?>">

            <?php
            get_the_image( array( 'size' => 'loop-main', 'width' => 160, 'height' => 120, 'before' => '<div class="cover">', 'after' => '</div>' ) );
            ?>

            <div class="postcontent">
                <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                <div class="postmetadata">
                    <ul>
                        <?php if (option::get('display_date') == 'on') { ?><li class="calendar"><time datetime="<?php the_time("Y-m-d"); ?>" pubdate><?php the_time("j F Y"); ?></time></li><?php } ?>
                        <?php if (option::get('display_author') == 'on') { ?><li class="author"><?php _e('By', 'wpzoom');?> <?php the_author_posts_link(); ?></li><?php } ?>
                        <?php if (option::get('display_category') == 'on') { ?><li class="category"><?php the_category(', '); ?></li><?php } ?>
                        <?php if (option::get('display_comments') == 'on') { ?><li class="comments"><?php comments_popup_link( __('0 comments', 'wpzoom'), __('1 comment', 'wpzoom'), __('% comments', 'wpzoom'), '', ''); ?></li><?php } ?>
                    </ul>
                </div><!-- end .postmetadata -->
                <?php the_excerpt(); ?>
                <p class="more"><a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>" class="readmore" rel="nofollow"><?php _e('continue reading &raquo;', 'wpzoom');?></a> <?php edit_post_link( __('Edit this post', 'wpzoom'), ' | ', ''); ?></p>
            </div><!-- end .postcontent -->

            <div class="cleaner">&nbsp;</div>
            <div class="sep">&nbsp;</div>
        </li><!-- end #post-<?php the_ID(); ?> -->
        <?php endwhile; //  ?>
    </ul>

    <div class="cleaner">&nbsp;</div>
    <?php else : ?>

    <p class="title"><?php _e('There are no posts in this category', 'wpzoom');?></p>

    <?php endif; ?>

    <?php get_template_part( 'pagination'); ?>

</div><!-- end .box -->
  • 写回答

1条回答 默认 最新

  • duanshanduo3363 2013-02-22 05:28
    关注

    You can do query_post just before the loop

    query_posts( array ( 'category_name' => 'my-category-slug' ) );
    

    If you want posts from more than one category then you can use

    query_posts('cat=8,4,3');
    

    8,4,3 are the id for the 3 categories

    and after the loop use

    wp_reset_query();
    

    For more details view this link

    http://codex.wordpress.org/Function_Reference/query_posts#All_Posts_in_a_Category

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 CATIA有些零件打开直接单机确定终止
  • ¥15 请问有会的吗,用MATLAB做
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 ARIMA模型时间序列预测用pathon解决
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序,怎么查看客户esp32板子上程序及烧录地址