• 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.

Viewing 10 replies - 1 through 10 (of 10 total)
  • <?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.

    Thread Starter syed544

    (@syed544)

    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.

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

    Thread Starter syed544

    (@syed544)

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

    Thanks again. Topic resolved.

    Thread Starter syed544

    (@syed544)

    @ 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.

    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.

    Thread Starter syed544

    (@syed544)

    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' );

    Thread Starter syed544

    (@syed544)

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

    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 https://php.net/manual/en/function.substr.php

    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

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Archive.php Show post links under each category’ is closed to new replies.