How to display posts under one catagory
-
Hi, I am currently using this snippet which I found on the net in a template
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; $args = array ( 'posts_per_page' => $posts_per_page, 'post_type' => 'post', 'orderby' => 'title', 'order' => 'ASC', 'paged' => $paged ); query_posts($args); if ( have_posts() ) { $in_this_row = 0; while ( have_posts() ) { the_post(); $first_letter = strtoupper(substr(apply_filters('the_title',$post->post_title),0,1)); if ($first_letter != $curr_letter) { if (++$post_count > 1) { end_prev_letter(); } start_new_letter($first_letter); $curr_letter = $first_letter; } if (++$in_this_row > $posts_per_row) { end_prev_row(); start_new_row(); ++$in_this_row; // Account for this first post } ?> <div class="title-cell"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></div> <?php } end_prev_letter(); ?> <div class="navigation"> <div class="alignleft"><?php next_posts_link('« Higher Letters') ?></div> <div class="alignright"><?php previous_posts_link('Lower Letters »') ?></div> </div> <?php } else { echo "<h2>Sorry, no posts were found!</h2>"; } ?> </div><!-- End id='a-z' -->Can anyone tell me how to edit it to show only posts from 1 category?
Viewing 2 replies - 1 through 2 (of 2 total)
-
add ‘category_name’ => ‘your-desired-category-name’ to your $args array.
more info hereThanks for the quick response, this has fixed the issue. Just to clarify if someone needs this for future reference I changed the array to this and it has done the trick.
$args = array ( 'posts_per_page' => $posts_per_page, 'post_type' => 'post', 'category_name' => 'category-slug-here', 'orderby' => 'title', 'order' => 'ASC', 'paged' => $paged
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘How to display posts under one catagory’ is closed to new replies.