是否将主页上的所有帖子更改为特定类别帖子?

时间:2011-07-06 作者:Prix

如何更改索引。php在主页中只显示所需的类别帖子?

我认为改变这一点可以锻炼身体,但它只是不打印任何内容:

            query_posts( array(
            \'post_type\' => array(
                        \'post\',
                        $include_reviews,
                        $include_screenshots,
                        $include_videos
                    ),
                    \'paged\' => $paged )
                );
更改自\'post\',\'cat=10\', 我不太清楚怎么做。

这是我的索引。php文件:

<?php get_header(); ?>

    <?php
    $slider_number = get_option(\'lp_slides_number\');
    $args = array( \'post_type\' => \'slider\', \'showposts\' => $slider_number );
    $slider_loop = new WP_Query( $args );
    if ($slider_loop->have_posts()) : ?>
    <!-- BEGIN SLIDER -->
    <div class="slider">

        <div class="sliderContent">

        <?php while ( $slider_loop->have_posts() ) : $slider_loop->the_post(); $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), false, \'\' ); ?>
            <div class="featured-item" style="background:<?php echo get_post_meta($post->ID, \'feature_bg\', true); ?> url(<?php echo $src[0]; ?>) no-repeat center; height:280px;">

                <div class="featured-inner">

                    <div class="featured-inner">

                        <div class="featured-arrows"></div>
                        <h1><a href="<?php echo get_post_meta($post->ID, \'feature_url\', true); ?>" rel="bookmark" title="Link Permanente: <?php the_title(); ?>"><?php the_title(); ?></a></h1>
                        <p class="featured-meta">Por <?php the_author(); ?>, <?php the_time( get_option(\'date_format\') ); ?></p>

                    </div>

                </div>

            </div>
        <?php endwhile;
        wp_reset_query(); ?>

        </div>

        <div class="top-overlay"></div>
        <div class="bottom-overlay"></div>

    </div>
    <!-- END SLIDER -->
    <?php endif; ?>

    <!-- BEGIN MAIN WRAPPER -->
    <div id="main-wrapper">

        <!-- BEGIN MAIN -->
        <div id="main">

            <!-- BEGIN NEWS WRAPPER -->
            <div id="news-wrapper">

                <h3 class="section-title">Last News</h3>

                <!-- BEGIN NEWS ITEMS -->
                <?php

                if(get_option(\'lp_include_reviews\') == "true") { $include_reviews = "\'reviews\',"; }
                if(get_option(\'lp_include_videos\') == "true") { $include_videos = "\'videos\',"; }
                if(get_option(\'lp_include_screenshots\') == "true") { $include_screenshots = "\'screenshots\',"; }

                query_posts( array(
                \'post_type\' => array(
                            \'post\',
                            $include_reviews,
                            $include_screenshots,
                            $include_videos
                        ),
                        \'paged\' => $paged )
                    );
                ?>
                <?php if (have_posts()) : ?>
                <?php while (have_posts()) : the_post(); ?>

                    <?php

                    if ( get_post_type() == \'reviews\' ) : ?>

                        <?php include( TEMPLATEPATH . \'/includes/show-reviews-frontpage.php\' ); ?>

                    <?php elseif ( get_post_type() == \'videos\' ) : ?>

                        <?php include( TEMPLATEPATH . \'/includes/show-videos-frontpage.php\' ); ?>

                    <?php elseif ( get_post_type() == \'screenshots\' ) : ?>

                        <?php include( TEMPLATEPATH . \'/includes/show-screenshots-frontpage.php\' ); ?>

                    <?php else: ?>

                        <?php include( TEMPLATEPATH . \'/includes/show-posts.php\' ); ?>

                    <?php endif; ?>

                <?php endwhile; ?>
                <?php kriesi_pagination(); ?>
                <?php wp_reset_query(); ?>

                <?php endif; ?>
                <!-- END NEWS ITEMS -->

            </div>
            <!-- END NEWS WRAPPER -->

        </div>
        <!-- END MAIN -->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

2 个回复
最合适的回答,由SO网友:Bainternet 整理而成

您的语法错误,请更改:

 query_posts( array(
                \'post_type\' => array(
                            \'post\',
                            $include_reviews,
                            $include_screenshots,
                            $include_videos
                        ),
                        \'paged\' => $paged )
                    );
收件人:

 query_posts( array(
        \'tax_query\' => array(
            array(
                \'taxonomy\' => \'category\',
                \'field\' => \'slug\',
                \'terms\' => array( $include_reviews,
                                $include_screenshots,
                                $include_videos )
            )),
        \'paged\' => $paged,
        \'post_type\' => \'post\')
);

SO网友:Ramkumar M

您好@:Prix请尝试此插件:Select Category to Post.它会起作用:)在这里,你可以根据自己的意愿选择类别,也可以像帖子一样发布该类别。

结束