badget

Biggest Sale! Special Offer!

Get 30% discount on all of our single themes with this coupon code: #30%SALE

Hurry up! *Limited time offer*

Reply To: Creating a page which lists posts from a specific category.

#27279
craig.haydon
Participant

Hi TH,
Unfortunately the get_posts (from above) didn’t work. (or at least i wasn’t able to get to work).
This is what i did to fix my question, and perhaps it will help other newbies like me.
1) created a new page template. (copy page.php and rename to page-template-page-blog.php)
2) added text (line 3) to the above new file (so its shows in WP admin). “* Template Name: Page with blog posts(cat=slug)”. You really can call it anything. The text that you enter here is what shows in WP admin (dashboard) in the page -> template (dropdown)
3) changed description to ‘* Displays posts in page based on slug’. This isn’t really necessary… but will help to remind you later what it does 🙂
4) modified content-extensions.php (its under library > structure) function attitude_theloop(){, so it now looks like this:

function attitude_theloop() {
	global $post;
	if( is_page() ) {
		if( is_page_template( 'page-template-blog-image-large.php' ) ) {
			attitude_theloop_for_template_blog_image_large();
		}
		elseif( is_page_template( 'page-template-blog-image-medium.php' ) ) {
			attitude_theloop_for_template_blog_image_medium();
		}
		elseif( is_page_template( 'page-template-blog-full-content.php' ) ) {
			attitude_theloop_for_template_blog_full_content();
		}
		elseif( is_page_template( 'page-template-page-blog.php' ) ) {
			$categ = $post->post_name;
			query_posts( "category_name=$categ&posts_per_page=10" );
			attitude_theloop_for_archive();
		}
		else {
			attitude_theloop_for_page();
		}
	}
	elseif( is_single() ) {
		attitude_theloop_for_single();
	}
	elseif( is_search() ) {
		attitude_theloop_for_search();
	}
	else {
		attitude_theloop_for_archive();
	}
}

5) back in wp-admin, go to the page you want to change, and change its template to ‘Page with blog posts(cat=slug)’.

There’s probable an even easier or better way to do this, but this is what worked for me… 🙂

Enjoy