WordPress.org

Ready to get started?Download WordPress

Forums

Archive.php Show post links under each category (11 posts)

  1. syed544
    Member
    Posted 3 years ago #

    I want to modify Archive.php file.
    Currently it is showing all posts links for a particular month.
    I want to display these posts links separately under each category.

    i.e.
    If I click on month July-2010, it should show all article links posted in this month of July, but like this :

    Category-1

    • link of post-1
    • link of post-2
    • link of post-3

    Category-2

    • link of post-1
    • link of post-2
    • link of post-3
    • link of post-4

    Category-3

    • link of post-1
    • link of post-2

    similarly showing all categories which have posts for July-2010.

    Thanks for helping.

  2. MichaelH
    Member
    Posted 3 years ago #

    <?php
    //get all terms (e.g. categories or post tags), then display all posts in each term
    $taxonomy = 'category';//  e.g. post_tag, category
    $param_type = 'category__in'; //  e.g. tag__in, category__in
    $term_args=array(
      'orderby' => 'name',
      'order' => 'ASC'
    );
    $terms = get_terms($taxonomy,$term_args);
    if ($terms) {
      foreach( $terms as $term ) {
        $args=array(
          "$param_type" => array($term->term_id),
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => -1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts in '.$taxonomy .' '.$term->name;
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
            <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
           <?php
          endwhile;
        }
      }
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Note see the Time Parameters in the query_posts() article.

  3. syed544
    Member
    Posted 3 years ago #

    MichaelH,
    Thanks a lot.
    Its exactly what which I needed badly.

    one thing more please.
    i want to show a tag-cloud after this code.
    i.e.
    I want to show all TAGS which are used under all posts of this particular month July-2010.
    please help again.

  4. MichaelH
    Member
    Posted 3 years ago #

    Maybe you can find a plugin that helps with that:
    http://www.google.com/search?q=wordpress+plugin+tag+cloud

  5. syed544
    Member
    Posted 3 years ago #

    Thanks MichaelH
    Though I dont like plugins, however I will try to get the code from these plugins.

    Thanks again. Topic resolved.

  6. syed544
    Member
    Posted 3 years ago #

    @ MichaelH,
    Theres a problem !!

    My need for the code was for :

    If I click on month July-2010, it should show all article links posted in this month of July

    But using the code above, it is showing all posts under each category, irrespective of the month.
    In other means, I need the code for the Archive.php file and not for Category.php file. I have to concern on each month's post by arranging under each category (present in the respective month).

    I hope you understand.
    Please help.

  7. MichaelH
    Member
    Posted 3 years ago #

    You'll need to access the 'm' query var with $year_month = get_query_var('m'); then separate that into year and month and use that in your query arguments...see query_posts() for those Time related parameters.

  8. syed544
    Member
    Posted 3 years ago #

    Sorry for duplicate thread!

    Can I access the month & year like this :

    $thismonth = get_query_var('monthnum')
    $thisyear = get_query_var('year')

    and then ..
    query_posts( 'monthnum=$thismonth&year=$thisyear' );

  9. syed544
    Member
    Posted 3 years ago #

    sorry. the code shall be like this:
    query_posts('year=' . $thisyear .'&monthnum=' .$thismonth );

  10. MichaelH
    Member
    Posted 3 years ago #

    Use this to list the query_vars:

    <?php 
    
    echo "<pre>"; print_r($wp_query->query_vars); echo "</pre>";
    
    ?>

    If I've got it right you need to use http://php.net/manual/en/function.substr.php

  11. cooljaz124
    Member
    Posted 3 years ago #

    Hi,

    I was trying to do something similar. To display on sidebar

    - April 2010
    - Post 1 // should be link
    - Post 2 // should be link
    - March 2010
    - Post 1 // should be link
    - Post 2 // should be link

    So, basically - showing all the monthly archives, but no link to "April 2010" or "March 2010" - but links to the posts within that point to their single.php.

    Hope the question is clear.

    Anyone with a solution ?
    Thanks in advance.

    Jaz

Topic Closed

This topic has been closed to new replies.

About this Topic