http://codex.ww.wp.xz.cn/Pages#Page_Templates
start with the code from index.php (depending on your theme) and use that as a starting point for a page template; then add a query before the start of the loop
http://codex.ww.wp.xz.cn/Function_Reference/query_posts
Why not to use WordPress built-in links to category pages?
So alchymyth what I have to do is duplicate the index.php (page template) and then add a query before the loop?
Oleg Dudkin what you mean by that? Sorry but I don’t know what you’re suggesting, it’s the first time I work with wordpress.
duplicate index.php and save as catposts-page-template.php (example only, use your own rememberable file name)
then add the neccessary lines at the top of that file; example:
<?php
/*
Template Name: Category Posts Template
*/
?>
then create a query and add this before the line with ‘if(have_posts())’ (start of the loop http://codex.ww.wp.xz.cn/The_Loop );
example:
<?php $args = array(
'category_name' => $post->post_name,
'paged' = get_query_var('paged')
);
query_posts( $args ); ?>
full set of possible query parameters: http://codex.ww.wp.xz.cn/Class_Reference/WP_Query#Parameters
alchymyth thank you for your help.
I got the idea but I can’t make it work yet. The name of my category is Nutrição and the URL is nutricao.
Can you give me a help on the code?
This is my nutricao-page-template.php
[code moderated - please use the pastebin for any code longer than 10 lines - see forum rules for posting code]
Here is the code: http://pastebin.com/ZCKjXGjM
Where and what exactly do I need do add about query?
You have 3 options:
1. Try to access http://your.site.com/category/nutricao – there should be category page with list of posts.
2. Add
<?php $args = array(
'category_name' => 'nutricao',
'paged' = get_query_var('paged')
);
query_posts( $args ); ?>
right after
<?php
/*
Template Name: Nutricao Posts Template
*/
?>
In this case you need 1 template for each category.
3. Similar as above, but use this code to insert.
<?php
global $posts;
$args = array(
'category_name' => $posts[0]->post_name,
'paged' = get_query_var('paged')
);
query_posts( $args ); ?>
In last case you need to name your page exactly like category is named. In your example – ‘nutricao’. But this template can be assigned to any number of pages.