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

Tagged: 

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #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?

      #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

        #10866
        wisefamily
        Customer

          Eric,

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

          Not sure if I want to post it here.

          #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

            #10898
            wisefamily
            Customer
              This reply has been marked as private.
              #10932
              wisefamily
              Customer

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

                #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.

                  #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' );
                    #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.

                      #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' );
                        #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.

                          #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.

                            #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.

                              #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.

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