WordPress.org

Ready to get started?Download WordPress

Forums

Two types of category listing (7 posts)

  1. Machi
    Member
    Posted 4 years ago #

    Hi there,
    I'm trying to solve one complicated post listing in categories. I'd like to display a three newest posts on a first level category differently than other posts.

    To understand my problem, please see this screenshot.

    The top level category displays three newest posts (float left blocks with pictures) and three older posts below it differently. Once you click a red button below them, another six posts should show (all six with the same style as three older posts, that means 6 posts instead of three).

    Other thing is a subcategory (eg. Photos - Whatever). The subcategory should display ONLY six posts with same style as three non-float posts.

    I have no idea how to solve this. I was trying to search for some is_first_page (in listing) function but I didn't find anything like that. It also doesn't solves the first-level and second-level difference.

    Thanks a lot for your help...

  2. MichaelH
    Member
    Posted 4 years ago #

  3. chinmoy
    Member
    Posted 4 years ago #

    Try this snapshot:

    $cat_title= single_cat_title();
    $cat_id = get_cat_id('',false);
    
    //first latest three category
    $query = new WP_Query("showposts=3");
    while($query->have_posts()) : $query->the_post();$do_not_duplicate = $post->ID;
    [Write your code here according to your design]
    
    //older three non-float posts
    $query = new WP_Query("showposts=3andoffsets=3");
    while($query->have_posts()) : $query->the_post();$do_not_duplicate = $post->ID;
    [Write your code here according to your design]
    
    //next six post
    $query = new WP_Query("showposts=6andoffsets=6");
    while($query->have_posts()) : $query->the_post();$do_not_duplicate = $post->ID;
    [Write your code here according to your design]

    For subcategory:

    $query = new WP_Query("showposts=6andchild_of=".$cat_id);
    while($query->have_posts()) : $query->the_post();$do_not_duplicate = $post->ID;
    [Write your code here according to your design]
  4. Machi
    Member
    Posted 4 years ago #

    Hi,
    thanks for the answers...

    MichaelH: I tried that but it's all related to styling certain categories differently, I need the same style for all first-level categories and other style for second level categories.

    chinmoy: Thanks a lot for your reply, however this doesn't solve two problems. How to recognize a category OR subcategory (this could be probably solved by http://wordpress.org/support/topic/292073?replies=5) and bigger issue... I want to display 3 float, 3 non float posts as you described. But other 6 (older) posts should be displayed by WP's paging function (that means six per page, multiple pages).

    Thanks a lot...

  5. chinmoy
    Member
    Posted 4 years ago #

    ok. Use wp-page-navi plugin for WP"s paging function.

  6. Machi
    Member
    Posted 4 years ago #

    Well, if it works with such customized outputs it would be awesome.

    Thanks for you replies :).

  7. MichaelH
    Member
    Posted 4 years ago #

    Just a note about depth of categories--here's two possibilities:

    <?php
    //test category 11 depth or level
    $max_depth_to_test = intval(9); //set this to highest depth you might have
    $last_depth = 0;
    $cat_to_test = 11;
    $category=get_category($cat_to_test);
    for ( $counter = 1; $counter <= $max_depth_to_test; $counter += 1) {
      if ($category->category_parent) {
        $category=get_category($category->category_parent);
        $last_depth = $counter;
      }
    }
    $last_depth +=1;
    echo '<p>Category ' . $cat_to_test . ' it is at depth ' . $last_depth .'</p>';
    ?>

    or

    <?php
    if ( cat_is_ancestor_of(6,20) ) {
      echo '<p>Category 6 an ancestor of category 20 </p>';
    } else {
      echo '<p>Category 6 is NOT an ancestor of category 20 </p>';
    }
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic