Cat list (not posts): display the latest postthumb (only one)?
-
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
- The topic ‘Cat list (not posts): display the latest postthumb (only one)?’ is closed to new replies.