Page of posts by $slug
-
I am making a theme and have a template page for a loop of posts and I want to use this template for 4 different categories. I did some searching through the codex, and think that what I need to alter is the query, not the loop. I should be able to run a standard loop after using a query like this:
if ( is_category( 'category-slug' ) ) : query_posts( array( 'category_name' => 'my-category-slug', 'posts_per_page' => -1 ) ); endif;
but is there a difference between ‘category-slug’ and ‘my-category-slug’? Let’s say a slug is “business” so should my code read:
if ( is_category( 'business' ) ) : query_posts( array( 'category_name' => 'business', 'posts_per_page' => -1 ) ); endif;
would I need to define ‘category_name’ somewhere (or is that a system recognized name?)
latest:
I found a single line that works where ‘business-for-sale’ is the (default?) slug for the category.
<?php query_posts( array( 'category_name' => 'business-for-sale', 'posts_per_page' => -1 ) ); ?>
I’m not sure what the php if statement is for, is it important?
Also, what can I put in that spot for the slug that would be a variable based on the current page (I need 4)?
Thanks for patience and understanding, this is my first WP theme and I’m learning php as I do it. [I posted originally in the wrong place, so I’m re-posting part of my thread with myself here]
- The topic ‘Page of posts by $slug’ is closed to new replies.