Support

Account

Home Forums General Issues Category List with thumbnails

Solved

Category List with thumbnails

  • I am trying to create a page with a list of all blog categories with an image for each category. (Basically a thumbnail grid of all categories)

    I created an Advanced Custom Field called “image” for categories.

    So far I have this:

    <?php
    
    $args = array( 'hide_empty' => '0');
    $categories = get_categories($args);
    if($categories){
    	echo '<ul>';
    	foreach($categories as $category) {
    		echo '<li>';
    		$size = "thumbnail";
    		$image = get_field('image', 'category_'.$category->term_id);    
    		echo '<img src="' . $image . '" />'; 
    		echo '<span class="cat-title">' . $category->name . '</span>';
    		echo '</li>';
    	} 
    	echo '</ul>';
    }    
    
    ?>
    

    This does output a list of categories and their images, but I also need each category image to link to the archive page for that category, and I need to get a specific size of the image. I have reached the limits of what my tiny amount of php knowledge can do. ๐Ÿ˜‰

  • https://developer.wordpress.org/reference/functions/get_term_link/

    
    <?php
    
    $args = array( 'hide_empty' => '0');
    $categories = get_categories($args);
    if($categories){
    	echo '<ul>';
    	foreach($categories as $category) {
    		$link = get_term_link($category);
    		echo '<li>';
    		$size = "thumbnail";
    		$image = get_field('image', 'category_'.$category->term_id);    
    		echo '<img src="' . $image . '" />'; 
    		echo '<span class="cat-title"><a href="'.$link.'">' . $category->name . '</a></span>';
    		echo '</li>';
    	} 
    	echo '</ul>';
    }    
    
    ?>
    
  • Thank you so much!

    • itzrana

    • September 16, 2020 at 4:41 pm

    how to show tag List with thumbnails

    • itzrana

    • September 16, 2020 at 5:31 pm
    <?php
    
    $args = array( 'orderby' => 'count', 'order' => 'DESC', 'number'=>2);
    $tags = get_tags($args);
    if($tags){
    	echo '<div id="dle-content">';
    	foreach($tags as $tag) {
    		$link = get_term_link($tag);
    		echo '<a href="'.$link.'">  <article class="movie-item movie-item1"> <div class="movie-cols movie-cols1 clearfix"> ';
    		$size = "thumbnail";
    		$image = get_field('tag_img', 'tag_'.$tag->term_id);    
    		echo ' <div class="movie-img movie-img1 img-box pseudo-link"> <div class="movie-img-inner"> <i class="fa fa-folder-open" data-link=""></i> </div> <img src="' . $image . '" />'; 
    		echo ' </div> <div class="movie-text movie-text1"> <div class="movie-title cardname">' . $tag->name . ' </div> </div> ';
    		echo ' </div> </article></a>';
    	} 
    	echo '</div>';
    }    
    
    ?>

    thumbnail is not showing

  • The name of the taxonomy for tags is actually “post_tag” so getting the field could look something like this

    
    $image = get_field('tag_img', 'post_tag_'.$tag->term_id);
    

    however, a lot has changed in 2 years. You could also use

    
    $image = get_field('tag_img', 'term_'.$tag->term_id);
    

    or even

    
    $image = get_field('tag_img', $tag);
    
    • itzrana

    • September 18, 2020 at 12:15 pm

    Thank You So Much

    • itzrana

    • September 18, 2020 at 12:18 pm

    Thanks

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.