tags:

views:

43

answers:

5

I want to display a list of post link group by year. Archive function don't do it Eg:

2010
  Blender 2.53 released
  Gamequery 0.5 released
  synfig 0.62.02 released
  ...

2009
  Gimp 2.67 released
  Blender 2.52 released

How can I do it?

A: 

I think you'll have to make your own custom query to get the posts by year. Something like this:

$query = $wpdb->prepare("SELECT * FROM $wpdb->blogs WHERE site_id = %d AND public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND last_updated != '0000-00-00 00:00:00' group by postyear", $wpdb->siteid );

Note: where I put "group by postyear", I'm not sure what that column name would be, so you'd have to figure out how that's stored in your blogs table. That may be a case where you have to parse out the year from a date field. Give that a shot. Then you can format your output like this:

$terms = $wpdb->get_results($query,ARRAY_A);
    echo "<ul>";    
    foreach($terms as $detail)
    {
        echo "<li style='font-size:1.3em;'><a href='http://".$detail[ 'domain' ].$detail['path']."'>".get_blog_option( $detail['blog_id'], 'blogname' )."</a></li>";
    }
    echo "</ul>";
Dylan West
A: 

You may want to try the following code:

wp_get_archives(array('type' => 'yearly'));

There are several more parameters to try. Please refer to http://codex.wordpress.org/Function_Reference/wp_get_archives for details.

boxoft
Second answer: it's generate a archive' list link to pages, not link to post !!
Henrique
Calm down please. I'm sure the wp_get_archives function generates links to posts. Please try "wp_get_archives(array('type' => 'postbypost'));"
boxoft
ok, but and year and category too?
Henrique
A: 

Query all your posts, ordered by post date (descending I assume?). You print them one by one, remember the year, and when the year of the current post is not the same as the year of the previous post, you know you have to print a year label.

query_posts(array('nopaging' => 1, /* we want all posts, so disable paging. Order by date is default */));
$prev_year = null;
if ( have_posts() ) {
   while ( have_posts() ) {
      the_post();
      $this_year = get_the_date('Y');
      if ($prev_year != $this_year) {
          // Year boundary
          if (!is_null($prev_year)) {
             // A list is already open, close it first
             echo '</ul>';
          }
          echo '<h3>' . $this_year . '</h3>';
          echo '<ul>';
      }
      echo '<li>';
      // Print the link to your post here, left as an exercise to the reader
      echo '</li>';
      $prev_year = $this_year;
   }
   echo '</ul>';
}
Jan Fabry
A: 

Jan, Thanks Now, I trying it filtering by a category and limit the post , but don't work

enter code here

1, /* we want all posts, so disable paging. Order by date is default */)); $prev_year = null;

query_posts('cat=4&posts_per_page=4&paged='.$paged.'');

if ( have_posts() ) {

Henrique
A: 
Henrique
@Henrique: If you want to reply, you should comment on an answer or edit your original question, otherwise I won't see it. I have corrected an error in my answer, and provided [a new answer on your followup question on WordPress Answers](http://wordpress.stackexchange.com/questions/1656/display-posts-links-from-a-category-group-by-year/2807#2807).
Jan Fabry