• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Appfinite

Appfinite

Premium WordPress Themes for The Genesis Framework

  • Themes
  • Blog
  • Tutorials and Resources
  • Forums
  • Contact Us

How To Build Your Own Related Posts Plugin On Epik

Home › Community Forums › Epik Theme Support › How To Build Your Own Related Posts Plugin On Epik

Tagged: related posts

  • This topic has 13 replies, 3 voices, and was last updated 8 years, 4 months ago by Wes.
Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • February 20, 2014 at 3:10 pm #10836
    wisefamily
    Customer

    I’m wanting to know how to properly add code into functions.php in Epik to have my own related posts at the bottom of each post.

    I don’t want to use a plugin because of site speed issues I’ve experienced in the past.

    This site helped but in Epik I couldn’t get the style to properly place the related posts part. It was always too far to the left and no matter what I did I couldn’t increase the margin.

    http://www.reginaldchan.net/display-related-posts-without-plugin-genesis/

    Has anyone ever done this manual process with Epik?

    February 21, 2014 at 9:51 pm #10859
    Eric
    Customer

    I haven’t done it myself, but if you add it on your site and send me the link, I can check to see if I can figure out what the issue is.


    I create awesome sites for awesome people! Contact me if interested – ericsanchez1585@gmail.com

    February 22, 2014 at 1:07 am #10866
    wisefamily
    Customer

    Eric,

    Thank you for replying. Where can I send you the link?

    Not sure if I want to post it here.

    February 22, 2014 at 9:23 pm #10877
    Eric
    Customer

    You can send it here if you want, just make sure to click the Private Reply box and we’ll be the only two that can see it.


    I create awesome sites for awesome people! Contact me if interested – ericsanchez1585@gmail.com

    February 24, 2014 at 12:36 am #10898
    wisefamily
    Customer
    This reply has been marked as private.
    February 25, 2014 at 8:52 am #10932
    wisefamily
    Customer

    I did the Private Reply box. Has anybody seen it yet? It’s reply #10898

    February 26, 2014 at 5:54 am #10956
    Wes
    Moderator

    I can probably help with this. How did you add the Related Posts at the end? I took a look at your code, but the div’s don’t have ID’s or Classes, which makes it difficult to style in the css. If there is a way to add an ID or Class to the divs then we can style it better with css.

    February 27, 2014 at 8:16 am #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' );
    February 28, 2014 at 6:43 am #11033
    Wes
    Moderator

    Ok just as I figured. You can add a class to the div that you added here – printf( '<div><h3>Related Posts</h3 Then style it how you want it to appear in your css.

    I’m unable to test that code you posted because it didn’t show up properly here in the forum…..some of it gets stripped out when added like regular text, plus it throws everything else on the thread off since there are extra divs and other code.

    Here’s how to add code in the forums – When you post code make sure to highlight the code and press the “code” button above in your toolbar so it can show up separately from regular text inside it’s own space….makes it easier to read, and nothing gets stripped out. I went ahead and edited your comment so you can see how it will look once you use it.

    February 28, 2014 at 10:59 am #11043
    wisefamily
    Customer
    /** Customize the post info function */
    add_filter( 'genesis_post_info', 'post_info_filter' );
    function post_info_filter($post_info) {
    if (!is_page()) {
    $post_info = 'by [post_author_posts_link] [post_comments] [post_edit]';
    return $post_info;
    }}
    
    /** 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' );
    February 28, 2014 at 11:00 am #11044
    wisefamily
    Customer

    Here’s the code. Sorry about that.

    Please test it when you can.

    I’d really like to get this fixed because I think it’s way better than a plugin bogging my sites down.

    February 28, 2014 at 6:14 pm #11064
    Wes
    Moderator

    Did you see my recent reply? You just need to add a class to the div that you’re adding and then style it how you want it to appear in your css.

    February 28, 2014 at 6:57 pm #11066
    wisefamily
    Customer

    Okay, I got it to work. Here’s what the style is currently:

    }
    
    .related-posts {
    margin: 10px  10px 10px 10px;
    }
    .related-posts h3 {
    font-size: 18px;
    }
    .related-posts ul {
    list-style:none;
    }
    .related-posts ul li {
    padding: 3px 0;
    border-bottom: 1px dashed #ccc;
    }
    .related-posts ul li a{
    font-size:14px;
    text-decoration:none;
    }

    How can I get a small picture to show up on the left of each post? It would pull from the actual post I guess.

    March 1, 2014 at 11:00 am #11073
    Wes
    Moderator

    I’m not sure how to do something like that, I would contact whoever you got the code from to see if they know of a way to do it.

  • Author
    Posts
Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.
Log In

Primary Sidebar

Search Forums

Affiliate Program

Looking to earn some money? Join our Affiliate program and earn 35% of every sale you refer. Top referrers earn 40-50%.

Join Now →

The Genesis Framework

All of our themes are designed for the Genesis Framework. You will need to purchase Genesis in order to use any of our themes.

Purchase Genesis

Hire a Web Developer

Need help setting up or customizing your website?

Contact Us →

Search Full Site

  • Buy Genesis!
  • Shopping Cart
  • Themes
  • My Account
  • Support Forums
  • Tutorials and Resources
  • Privacy Policy
  • Contact Us
  • Follow Us on Twitter

Copyright © 2022 · Appfinite · Built With The Genesis Framework