Grow your CSS skills. Land your dream job.

Custom WordPress Archives Page

  • # November 17, 2011 at 4:24 pm

    Sample Image

    Basically what I am hoping to accomplish is this:

    1) Nothing displays on the page at first except the row of Years
    2) User clicks on year and it loads the associated months in that row
    3) User clicks on specific month and it loads the posts below in that area

    I am having a hell of a time trying to figure out how best to accomplish this, any ideas to help point me in the right direction would be greatly appreciated.

    < ?php
    /*
    Template Name: Custom Archives
    */
    ?>
    < ?php get_header(); ?>

    Blog: Archives


    /blog" title="Latest Posts" id="back-to-posts">Latest Posts





    Select a Year



      < ?php
      $years = $wpdb->get_col("SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' ORDER BY post_date DESC");
      foreach($years as $year):
      ?>
    • " title="< ?php echo $year; ?>">< ?php echo $year; ?>

    • < ?php endforeach; ?>




      < ?php
      $months = $wpdb->get_col("SELECT DISTINCT MONTH(post_date) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND YEAR(post_date) = '".$year."' ORDER BY post_date DESC");
      foreach($months as $month):
      ?>
    • ">< ?php echo date('F', mktime(0, 0, 0, $month)); ?>

    • < ?php endforeach; ?>




    < ?php
    //Query Posts by Year and Month Selected
    $monthly_posts = query_posts("cat=1&year=".$year."&monthnum=".$month."&order=DESC");

    //Count Returned Posts
    $post_count = count($monthly_posts);
    ?>


    < ?php
    if($post_count == 1)
    {
    echo $post_count.' blog post found';
    } else
    {
    echo $post_count.' blog posts found';
    }
    ?>





      < ?php
      //If Posts Exist Display in List
      if(have_posts()): while(have_posts()) : the_post();
      ?>
    • ">< ?php the_title(); ?>

    • < ?php
      //End Post Loop
      endwhile;
      //End Post IF
      endif;
      wp_reset_query();
      ?>






    < ?php get_footer(); ?>
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".