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.

I have three pages on my site (Listen, Read, Watch) which each query a different post category: "listen", "read", and "watch" respectively. I created three separate php files with their own unique template names and I created a Page in the wp-admin and selected the appropriate template for each. I am having trouble using the below query multiple times. For example, Listen page will query the "listen" category successfully with pagination; however, I am unable to use the same code on the other two pages.

            <?php
            /*
            Template Name: Listen
            */
            ?>

            <!-- header.php -->
            <?php get_header(); ?>
            <!-- /header.php -->

            <!-- 960 16 Column Grid -->
            <div class="container_16"> 

                <!-- Featured News -->
                <section class="grid_10 read">

                    <!-- Featured News Heading -->
                    <h1></h1>
                    <!-- /Featured News Heading -->

                        <!-- Featured News Loop -->
                        <?php
                            $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
                                $args=array(
                                    'post_type'=>'post',
                                    'cat' => 'listen',
                                    'posts_per_page' => 5,
                                    'paged'=>$paged
                                );
                                $temp = $wp_query;
                                $wp_query= null;
                                $wp_query = new WP_Query($args);

                            if (function_exists('wp_pagenavi')) { wp_pagenavi(); }
                            if ( $wp_query->have_posts() ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
                        ?> 

                        <!-- Post --> 
                        <article class="post">

                            <!-- Featured News Title -->
                            <span><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( '%s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
                            </span>
                            <!-- /Featured News Title -->

                            <!-- Featured News Meta -->
                            <p class="featured-news-post-meta">By <span class="featured-news-author"><?php echo get_the_author(); ?></span> / <?php echo get_the_date('d.m.Y'); ?>
                            </p>
                            <!-- /Featured News Meta -->

                            <!-- Featured News Thumbnail -->
                            <?php the_post_thumbnail(array(640,320)); ?>
                            <!-- /Featured News Thumbnail -->

                            <!-- Featured News Excerpt -->
                            <p class="featured-news-excerpt"><?php the_excerpt(); ?></p>
                            <!-- /Featured News Excerpt -->

                            <!-- Featured News Social Links -->
                            <?php include('includes/social.php'); ?>
                            <!-- /Featured News Social Links -->

                        </article>
                        <!-- /Post -->

                        <?php endwhile; endif; ?>
                        <!-- /Featured News Loop -->

                        <!-- Pagination -->
                        <?php if ($wp_query->max_num_pages > 1) : ?>
                            <div class="grid_10 pagination older-news">
                                <?php next_posts_link( __( '<span class="arrow">&larr;</span> Older News', 'twentyten' ) ); ?>
                                <div class="pagination newer-news">
                                <?php previous_posts_link( __( 'Newer News <span class="arrow">&rarr;</span>', 'twentyten' ) ); ?>
                                </div>
                            </div>
                        <?php endif; ?>
                        <!-- /Pagination -->

                        <?php
                        /* PageNavi at Bottom */
                        if (function_exists('wp_pagenavi')){wp_pagenavi();}
                        $wp_query = null;
                        $wp_query = $temp;
                        wp_reset_query();
                        ?>
                        <!-- /Featured News Loop -->

                </section>
                <!-- /Featured News -->

                <!-- Other News -->
                <aside class="grid_5 other-news read-other-news">

                    <!-- Other News Heading -->
                    <h3></h3>
                    <!-- /Other News Heading -->

                        <!-- Other News Loop -->
                        <?php query_posts('category_name=other-news&showposts=6'); ?>
                        <?php while (have_posts()) : the_post(); ?>

                        <!-- Other News List -->
                        <ul>
                            <li><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
                            </li>
                            <li class="other-news-post-date"><?php echo get_the_date('d.m.Y'); ?>
                            </li>
                        </ul>
                        <!-- /Other News List -->

                        <?php endwhile; ?>
                        <!-- /Other News Loop -->

                        <!-- View More -->
                        <div class="view-more">
                            <a href="/other-news">View More &rarr;</a>
                        <div>
                        <!-- /View More -->

                </aside>
                <!-- /Other News -->

            </div>
            <!-- /960 16 Column Grid -->

            <!-- sidebar.php -->
            <?php get_sidebar(); ?>
            <!-- /sidebar.php -->

            <!-- footer.php -->
            <?php get_footer(); ?>
            <!-- /footer.php -->
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

cat requires an ID, if you're using the slug, set category_name instead. see WP_Query Category Parameters.

share|improve this answer
    
Brilliant. Thank you. –  Brian Jun 23 '12 at 16:03
add comment

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.