Reply To: How To Build Your Own Related Posts Plugin On Epik

Homepage › Community Forums › Epik Theme Support › How To Build Your Own Related Posts Plugin On Epik › Reply To: How To Build Your Own Related Posts Plugin On Epik

#11023
wisefamily
Customer

    This is the code I added at the end.

    /** Display related posts in Genesis based on Category */
    function related_posts_categories() {
    if ( is_single ( ) ) {
    global $post;
    $count = 0;
    $postIDs = array( $post->ID );
    $related = '';
    $cats = wp_get_post_categories( $post->ID );
    $catIDs = array( );{
    foreach ( $cats as $cat ) {
    $catIDs[] = $cat;
    }
    $args = array(
    'category__in' => $catIDs,
    'post__not_in' => $postIDs,
    'showposts' => 5,
    '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();
    $related .= '<li><a href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to' . get_the_title() . '">' . get_the_title() . '</a></li>';
    }
    }
    }
    if ( $related ) {
    printf( '<div><h3>Related Posts</h3><ul>%s</ul></div>', $related );
    }
    wp_reset_query();
    }
    }
    add_action( 'genesis_after_entry_content', 'related_posts_categories' );