• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Related Posts with Thumbnails

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Related Posts with Thumbnails

This topic is: not resolved
  • This topic has 1 reply, 2 voices, and was last updated 10 years, 5 months ago by Christoph.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • May 15, 2016 at 8:36 am #185356
    vangelisbel
    Member

    Hello

    I have been using a script for Related Posts with Thumbnails and it worked great. However ever since I changed the number of related posts from 5 to 3, I only see the same 3 related posts under every post of a category (I don't know if that is the problem though).
    E.g. The posts in the following category:
    http://www.vangelisphotography.com/santorini-wedding/

    Do you think there is a problem with the script below?

    /** Display related posts in Genesis based on Category */
    //for HTML5 themes
    add_action( 'genesis_after_entry_content', 'child_related_posts' );
    /**
    * Outputs related posts with thumbnail
    */
    function child_related_posts() {

    if ( is_single ( ) ) {

    global $post;

    $count = 0;
    $postIDs = array( $post->ID );
    $related = '';
    $tags = wp_get_post_tags( $post->ID );
    $cats = wp_get_post_categories( $post->ID );

    if ( $tags ) {

    foreach ( $tags as $tag ) {

    $tagID[] = $tag->term_id;

    }

    $args = array(
    'tag__in' => $tagID,
    'post__not_in' => $postIDs,
    'showposts' => 3,
    'ignore_sticky_posts' => 1,
    'tax_query' => array(
    array(
    'taxonomy' => 'post_format',
    'field' => 'slug',
    'terms' => array(
    'post-format-link',
    'post-format-status',
    'post-format-aside',
    'post-format-quote'
    ),
    'operator' => 'NOT IN'
    )
    )
    );

    $tag_query = new WP_Query( $args );

    if ( $tag_query->have_posts() ) {

    while ( $tag_query->have_posts() ) {

    $tag_query->the_post();

    $img = genesis_get_image() ? genesis_get_image( array( 'size' => 'related' ) ) : '' . get_the_title() . '';

    $related .= '

    • ' . $img . get_the_title() . '

    ';

    $postIDs[] = $post->ID;

    $count++;
    }
    }
    }

    if ( $count <= 4 ) {

    $catIDs = array( );

    foreach ( $cats as $cat ) {

    if ( 3 == $cat )
    continue;
    $catIDs[] = $cat;

    }

    $showposts = 3 - $count;

    $args = array(
    'category__in' => $catIDs,
    'post__not_in' => $postIDs,
    'showposts' => $showposts,
    'ignore_sticky_posts' => 1,
    'orderby' => 'rand',
    'tax_query' => array(
    array(
    'taxonomy' => 'post_format',
    'field' => 'slug',
    'terms' => array(
    'post-format-link',
    'post-format-status',
    'post-format-aside',
    'post-format-quote' ),
    'operator' => 'NOT IN'
    )
    )
    );

    $cat_query = new WP_Query( $args );

    if ( $cat_query->have_posts() ) {

    while ( $cat_query->have_posts() ) {

    $cat_query->the_post();

    $img = genesis_get_image() ? genesis_get_image( array( 'size' => 'related' ) ) : '' . get_the_title() . '';

    $related .= '

    • ' . $img . get_the_title() . '

    ';
    }
    }
    }

    if ( $related ) {

    printf( '<div class="related-posts"><h3 class="related-title">You May Also Like</h3><ul class="related-list">%s</div>', $related );

    }

    wp_reset_query();

    }
    }

    June 1, 2016 at 1:02 am #186659
    Christoph
    Member

    Hi,

    when you add code, please wrap in code tags (the button that says code right above the editor).
    I would also haven been nice if you had added a link to the original code. I think you got it from here http://mygenesisthemes.com/related-posts-genesis/

    Without testing the script, it looks like you didn't adjust this part of the code

     if ( $count <= 4 ) {
    
    $catIDs = array( );
    
    foreach ( $cats as $cat ) {
    
    if ( 3 == $cat )
    continue;
    $catIDs[] = $cat;

    I would guess that would have to be 3 and 2, respectively.


    https://www.christophherr.com | Genesis Customizations | Buy me a coffee

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble