如何在不同的页面中显示不同的类别?

时间:2014-04-10 作者:bear

我有这个博客网页和一个最新新闻网页。现在,两个页面显示的是同一个类别。如何将它们分开?那么一个页面显示类别1,另一个页面显示类别2?

category\\u博客的代码。php

<!--<tm_category>-->

<!--<div if else tm_category>-->
<?php if ( is_active_sidebar( \'category-sidebar-widget-left\' ) && is_active_sidebar( \'category-sidebar-widget-right\' ) ) { ?>
<div class="tm_category_2">

<?php } elseif ( is_active_sidebar( \'category-sidebar-widget-left\' ) ) { ?>
<div class="tm_category_1">

<?php } elseif ( is_active_sidebar( \'category-sidebar-widget-right\' ) ) { ?>
<div class="tm_category_1_right">

<?php } else { ?>
<div class="tm_category_0">

<?php } ?>
<!--</div if else tm middle post>-->

    <!--<category name>-->
    <div class="tm_cat_metatitle">
        <h1>
            <i class="icon-reorder"></i> 
            <?php echo single_cat_title( \'\', false ); ?> 
        </h1> 
        <div class="tm_cat_arrow"></div>
    </div>
    <!--</category name>-->

    <!--<tm_category_file>-->
    <div class="tm_category_file">
        <div class="tm_category_box">

        <?php if ( have_posts() ) : ?>

            <!--<the loop>-->
            <?php while ( have_posts() ) : the_post(); ?>
            <div <?php post_class(); ?>>

                <!--<cat title>-->
                <div class="tm_catpost_titles">
                        <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
                            <h1 class="tmpost-<?php the_ID(); ?>">
                            <?php $tit = the_title(\'\',\'\',FALSE); echo substr($tit, 0, 150); if (strlen($tit) > 150) echo " ..."; ?>
                            </h1>
                        </a>
                </div>
                <!--</cat title>-->     

                <!--<cat item>-->
                <div class="tm_cat_item">
                    <div class="tmpost-<?php the_ID(); ?>-item">

                        <div class="tm_catpost_item_1">
                        <i class="icon-user"></i> 
                        <?php _e(\'By\', \'tm_myid_text\'); ?> <?php the_author(); ?>
                        </div>

                        <div class="tm_catpost_item_2">
                        <i class="icon-tag"></i> 
                        <?php _e(\'In\', \'tm_myid_text\'); ?> <?php $category = get_the_category(); echo $category[0]->cat_name; ?>
                        </div>

                        <div class="tm_catpost_item_3">
                        <i class="icon-calendar"></i>
                        <?php the_time(\'M jS, Y\') ?>
                        </div>

                        <div class="tm_catpost_item_4">
                        <i class="icon-comments"></i> 
                        <?php comments_number(__(\'0 Comments\', \'tm_myid_text\'), __(\'1 Comment\', \'tm_myid_text\'), __( \'% Comments\', \'tm_myid_text\') );?>
                        </div>

                        <div class="tm_catpost_item_5">
                        <i class="icon-eye-open"></i> 
                        <?php echo tm_viewcounter_display(get_the_ID()); ?>
                        </div>

                    </div>
                </div>
                <!--</cat item>-->

                <!--<cat image>-->
                <div class="tm_cat_image">
                <?php if (has_post_thumbnail()) { ?>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <?php the_post_thumbnail( \'full\' ); ?>
                    </a>
                <?php } else { ?>
                <?php } ?>
                </div>
                <!--</cat image>-->

                <div class="tm_cat_desc">
                    <div class="tmpost-desc">
                    <?php echo excerpt(300); ?> 
                    </div>

                    <div class="tm_cat_readmore">
                        <div class="tmpost-readmore">
                            <a href="<?php the_permalink() ?>">
                                <i class="icon-file-text"></i> 
                                <?php _e(\'Read More\', \'tm_myid_text\'); ?>
                            </a>
                            <div class="tmpost-readmore_list"></div>
                        </div>
                    </div>

                </div>

            </div>
            <?php endwhile; ?>
            <!--</the loop>-->

        </div>
    </div>
    <!--</tm_category_file>-->

    <!--<tm pagination>-->
    <div id="Nav">
        <div class="tm_navigation">
        <?php echo tm_pagination_nav(); ?>
        </div>
    </div>
    <!--</tm pagination>-->

        <?php else : ?>
        <?php endif; ?>

</div>
<!--</tm_category>-->
这是索引代码:

<?php 
/* Template Name: Home 5 */
?>

<?php get_header(); ?>

<!--<home 5>-->

<!--<div tm_category 0>-->
<div class="tm_category_0">
<!--</div tm_middle 0>-->

    <!--<category name>-->
    <div class="tm_cat_metatitle">
        <h1>
            <i class="icon-reorder"></i> 
             Recent Posts           
        </h1> 
        <div class="tm_cat_arrow"></div>
    </div>
    <!--</category name>-->

    <!--<tm_category_file>-->
    <div class="tm_category_file">
        <div class="tm_category_box_home5">

        <?php if ( have_posts() ) : ?>

            <!--<the loop>-->
            <?php $wp_query = new WP_Query( array( 
                                                "cat" => "", 
                                                "posts_per_page" => "", 
                                                "post_type" => "post",
                                                "paged" => get_query_var(\'paged\') ? get_query_var(\'paged\') : 1
                                                )                                               
                                        );
            while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>

            <div <?php post_class(); ?>>

                <!--<cat title>-->
                <div class="tm_catpost_titles">
                        <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>">
                            <h1 class="tmpost-<?php the_ID(); ?>">
                            <?php $tit = the_title(\'\',\'\',FALSE); echo substr($tit, 0, 150); if (strlen($tit) > 150) echo " ..."; ?>
                            </h1>
                        </a>
                </div>
                <!--</cat title>-->     

                <!--<cat item>-->
                <div class="tm_cat_item">
                    <div class="tmpost-<?php the_ID(); ?>-item">

                        <div class="tm_catpost_item_1">
                        <i class="icon-user"></i> 
                        <?php _e(\'By\', \'tm_myid_text\'); ?> <?php the_author(); ?>
                        </div>

                        <div class="tm_catpost_item_2">
                        <i class="icon-tag"></i> 
                        In <?php $category = get_the_category(); echo $category[0]->cat_name; ?>
                        </div>

                        <div class="tm_catpost_item_3">
                        <i class="icon-calendar"></i>
                        <?php the_time(\'M jS, Y\') ?>
                        </div>

                        <div class="tm_catpost_item_4">
                        <i class="icon-comments"></i> 
                        <?php comments_number(__(\'0 Comments\', \'tm_myid_text\'), __(\'1 Comment\', \'tm_myid_text\'), __( \'% Comments\', \'tm_myid_text\') );?>
                        </div>

                        <div class="tm_catpost_item_5">
                        <i class="icon-eye-open"></i> 
                        /*<?php echo tm_viewcounter_display(get_the_ID()); ?>/*
                        </div>

                    </div>
                </div>
                <!--</cat item>-->

                <!--<cat image>-->
                <div class="tm_cat_image">
                <?php if (has_post_thumbnail()) { ?>
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                    <?php the_post_thumbnail( \'Full\' ); ?>
                    </a>
                <?php } else { ?>
                <?php } ?>
                </div>
                <!--</cat image>-->

                <div class="tm_cat_desc_home5">
                    <div class="tmpost-desc">
                    <?php the_content(); ?>
                    </div>

                    <div class="tm_cat_readmore">

                        <div class="tmpost-readmore">
                            <a href="<?php the_permalink() ?>">
                                <i class="icon-file-text"></i> 
                                 <?php comments_number(__(\'(0) Kommentarer \', \'tm_myid_text\'), __(\'(1) Kommentar\', \'tm_myid_text\'), __( \'(%) Kommentarer\', \'tm_myid_text\') );?> 
                            </a>
                            <div class="tmpost-readmore_list"></div>
                        </div>
                    </div>

                </div>

            </div>

            <?php endwhile; ?>
            <!--</the loop>-->

        </div>
    </div>
    <!--</tm_category_file>-->

    <!--<tm pagination>-->
    <div id="Nav">
        <div class="tm_navigation">
        <?php echo tm_pagination_nav(); ?>
        </div>
    </div>
    <!--</tm pagination>-->

        <?php else : ?>
        <?php endif; ?>

</div>

<!--</home left>-->
<?php get_template_part( \'sidebar_left\' ); ?>
<!--</home left>-->
<!--</home 5>-->

<?php get_footer(); ?>

1 个回复
SO网友:user48752

更改cat 到您想要的类别编号。例如:

 "cat" => 2, 
或者,如果您知道类别名称,也可以使用:

"category" =>"category_name", 
您应该在wp_query 下面的参数为空:

$wp_query = new WP_Query( array( 
                                                    "cat" => "", 
                                                    "posts_per_page" => "", 
                                                    "post_type" => "post",
                                                    "paged" => get_query_var(\'paged\') ? get_query_var(\'paged\') : 1
                                                    )                                               
                                            );

结束

相关推荐

如何在GET_POSTS Foreach循环中使用WordPress条件标记

我有一个页面jquery tab function 输出此页面的子页面列表(Bio、Archives、Contact)。然而,我试图在foreach循环中设置一个条件,但没有任何效果。<?php // get_posts function: http://codex.wordpress.org/Template_Tags/get_posts#Examples $args = array( \'paged\' => $paged, \'post_type