Support » Plugins » Hacks » Cat list (not posts): display the latest postthumb (only one)?

  • Resolved Nathira

    (@nathira)


    Hi,
    I need help 🙂
    I can’t code php and I’m building my site with code snippets and a lot of trial and error 😛

    Let me explain what I’m trying to do:
    I have a post category called “Alben” (english: albums). This category has some child categories (like scenes or portraits). When I upload a new picture I create a post for it in one of the child categories.

    I created a special template for “Alben”. When I click on “Alben” in my menue I get a page listing only the child category names, links and posts counts (no posts yet). Posts are only shown when I click on a child category name.

    I would now like to display the post thumbnail of the latest post in my child category on my special page under the child cat name.

    Is this possible?

    Here is the code I used to get and display the child categories:

    <?php
    	//for this category on an archive page, get the ID
    	$thisID = get_query_var('cat');
    
    	$get_children_cats = array(
    		'child_of' => $thisID //get children of this parent using the thisID variable from earlier
    	);
    
    	$child_cats = get_categories( $get_children_cats );//get children of this parent category
    
    	foreach( $child_cats as $child_cat ) {
    
    		//for each child category, get the ID
    		$childID = $child_cat->cat_ID;
    
    		//for each child category, give us the link and name and description
    
    		if ($counter == 2 || $counter == 5) {
    		echo '<div class="col"><h2><a href=" ' . get_category_link( $childID ) . ' ">' . $child_cat->name . '</a></h2><br/>';
    		echo '<div>' . $child_cat->category_description . '</div>';
    		echo '<div> Bilder: ' . $child_cat->category_count . '</div></div>';
    
    		}else{
    		echo '<div class="col-1"><h2><a href=" ' . get_category_link( $childID ) . ' ">' . $child_cat->name . '</a></h2><br/>';
    		echo '<div>' . $child_cat->category_description . '</div>';
    		echo '<div> Bilder: ' . $child_cat->category_count . '</div></div>';
    	}
    	$counter++;
    } //end of categories logic
    ?>

    I use two different divs because I display the child categories in 3 columns and the third div in each row has no margin-right. Just to explain the stuff up there a bit.

    The site is not online, so I can’t give a link. But I have a picture 😛
    Picture

Viewing 1 replies (of 1 total)
  • Done! 😛

    I found a code for a query which lists only one post of every child category in a parent category.
    I modified that code to display the child cat name with link, the post thumbnail with link to the child cat and the cat post count.
    When that worked, I put the counter back in to wrap each entry in one of the two different divs.

    I removed the automatic post thumb linking from my functions.php to link the thumb to the cat and not the post, but that is ok for me. I now link my post thumbs manually 🙂

Viewing 1 replies (of 1 total)
  • The topic ‘Cat list (not posts): display the latest postthumb (only one)?’ is closed to new replies.