Chronosbox

Snippets

Wordpress template page for categorized posts.

by Felipe 'chronos' Prenholato on 02:11 AM, under Snippets, Wordpress

Fast code snippet to get one page template that show posts of one category:

Add in your template page following code:

<?
the_post();
$keys = get_post_custom_keys();
if(in_array("category",$keys)) {
	$categoryslug = get_post_custom_values("category");
	query_posts('category_name='.$categoryslug[0]);
}
?>

Now, in your page add a custom field named ‘category’, field value is slug name of category.

Save the page and be happy! Now you can use same template for various pages and show any category without change more PHP code :) .

6 Comments :, , , , more...

StatPress

Visits today: 26 Visits since 6 de April de 2009: 16053 Visitors now: %visitoronline%