Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I change my index.php to display only the desired categories posts in the main page ?

I tought that changing this would workout but instead it just print nothing:

            query_posts( array(
            'post_type' => array(
                        'post',
                        $include_reviews,
                        $include_screenshots,
                        $include_videos
                    ),
                    'paged' => $paged )
                );

Change from 'post', to 'cat=10', not very sure how to do this.

This is my index.php file:

<?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(); ?>
share|improve this question

2 Answers 2

up vote 1 down vote accepted

Your syntax is wrong, change:

 query_posts( array(
                'post_type' => array(
                            'post',
                            $include_reviews,
                            $include_screenshots,
                            $include_videos
                        ),
                        'paged' => $paged )
                    );

to:

 query_posts( array(
        'tax_query' => array(
            array(
                'taxonomy' => 'category',
                'field' => 'slug',
                'terms' => array( $include_reviews,
                                $include_screenshots,
                                $include_videos )
            )),
        'paged' => $paged,
        'post_type' => 'post')
);
share|improve this answer
    
it is not about the $include_..., they work just fine it is about not printing all posts in the blog but just posts in a selected category. –  Prix Jul 6 '11 at 11:12
    
what???? i guess i don't understand your question –  Bainternet Jul 6 '11 at 11:18

Hi @:Prix Try this Plugin: Select Category to Post.It'll work:)Here You Select Category as your wish and also post that category like posts.

share|improve this answer
    
How would I use it to display on the index.php only the pre-defined categories I want (no user interaction) the plugin page does not show any information on the usage ? –  Prix Jul 6 '11 at 12:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.