tsimages
Member
Posted 2 years ago #
I'm new to using php and what not, so forgive me if this is all too obvious, but I can't for the life of me figure out how to modify the page of posts php code to show posts using a category name.
I've created a template php doc for my page with the page of posts code, but can't find any examples of how to modify this code so that the template will display posts of a certain category by name.
Can someone please post an example of what that should look like? I've used the page of posts code on the following page:
http://codex.wordpress.org/Pages
Thanks in advance
Try:
<?php
if (is_page('About') ) $cat_name = 'Foo';
elseif ( is_page('One') ) $cat_name = 'Bar';
else $cat_name = '';
$posts_per_page = -1; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$args=array(
'category_name' => $cat_name,
'posts_per_page' => $posts_per_page,
'caller_get_posts' => $do_not_show_stickies
);
$my_query = new WP_Query($args);
?>
tsimages
Member
Posted 2 years ago #
Thanks
Am I correct in assuming that i need to substitute my page name for "About" and my category name for "Foo"?
Yes - those were just random page & catgeory names for the example.