Search code examples
wordpressarchive

Wordpress Archive by Year "query_posts()" Problem


I created an Archive list (also this is my archive.php codes) on my blog and i want to show posts by years.

But when i use query_posts() function for excluding some categories and limit posts then it's showing all posts not by year.

For example this page is showing all posts not only posts in 2009 years.

So if i summarize this issue; i want to show archive list by year (when i enter /2009/ permalink)+exclude some categories and limit posts.

Thank you.


Solution

  • maybe when you use global variable, $query_string, it will help.

    so you must use it like this

    global $query_string;
    query_posts($query_string . '&cat=-13,-4,-14,-171&posts_per_page=5&paged='. $paged);
    

    as codex mention, here : query post,

    Place a call to query_posts() in one of your Template files before The Loop begins. The wp_query object will generate a new SQL query using your parameters. When you do this, WordPress ignores the other parameters it receives via the URL (such as page number or category). If you want to preserve that information, you can use the $query_string global variable in the call to query_posts().