tags:

views:

79

answers:

3

I would like to change the default behavior of Wordpress regarding the number of articles displayed on a same page to be the following :

  • when displaying the home page, the 10 most recent articles should be displayed, 10 being the setting which can be changed through the admin panel (posts_per_page)
  • when displaying the articles of a specific month (given through the URL like this : ?m=200906&order=ASC, I'd like to display on the same page all articles of this month (in other words, I don't want to have to browse through articles using previous entries or next entries.

EDIT : I forgot something else I'd like to change :

On the page where all articles of the specified month are displayed, I would like to display the comments for each article.

Is this possible to do ? How ?

A: 

You can probably do this using query_post if you look at the codex page it gives you details of how to do this:

http://codex.wordpress.org/Template_Tags/query_posts

matpol
A: 

Check out WP_query also there are some differences between query_posts and WP_query. Both are used to create queries for custom loop. If you want better control over query use WP_query.

  1. http://codex.wordpress.org/Custom_Queries
  2. http://codex.wordpress.org/Function_Reference/WP_Query
  3. http://codex.wordpress.org/Template_Tags/query_posts
Pragati Sureka
+3  A: 

in your archive.php, add this on top of your template:

$allowedOrder = array('ASC', 'DESC');
if(isset($_GET['m'])){
   $order = isset($_GET['order']) ? (in_array($_GET['order'], $allowedOrder) ? $_GET['order'] : $allowedOrder[0]) : $allowedOrder[0];
   $m = $_GET['m'];
   $y = substr($m, 0, 4);
   $m = substr($m, -2);
   $query = "posts_per_page=-1&year=$y&monthnum=$m&order=$order";
   query_posts($query);
 }

Or, if you just have one big index.php template file, do this:

$allowedOrder = array('ASC', 'DESC');
if(is_month()){
   $order = isset($_GET['order']) ? (in_array($_GET['order'], $allowedOrder) ? $_GET['order'] : $allowedOrder[0]) : $allowedOrder[0];
   $m = $_GET['m'];
   $y = substr($m, 0, 4);
   $m = substr($m, -2);
   $query = "posts_per_page=-1&year=$y&monthnum=$m&order=$order";
   query_posts($query);
}

For more detail, look at codex page:

silent
thanks for the tip. I added the code to my archive.php and it working fine, except that now, I cannot use anymore the order=ASC (see updated question). Am I doing something wrong ?Also, do you have an idea how to display all comments after each displayed article ?
Jérôme
you know, query_posts can fix that for you. Just add 'order=ASC' to $query. As for second question (comments on each article) you can open up another SO question with detailed problem. post it here so that I can see the URL.
silent
If I understand well, adding the sorting in $query will force this sorting, where I would prefer to get the sorting given through the URL. Any idea how to do this ?
Jérôme
see my new SO question regarding comments : http://stackoverflow.com/questions/2409988/wordpress-always-display-comments-with-articles
Jérôme
I've updated my answer to reflect that. check out
silent