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.
-
AuthorPosts
-
February 20, 2014 at 3:10 pm #10836
wisefamily
CustomerI’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 #10859Eric
CustomerI 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 #10866wisefamily
CustomerEric,
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 #10877Eric
CustomerYou 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 #10898wisefamily
CustomerThis reply has been marked as private.February 25, 2014 at 8:52 am #10932wisefamily
CustomerI did the Private Reply box. Has anybody seen it yet? It’s reply #10898
February 26, 2014 at 5:54 am #10956Wes
ModeratorI 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 #11023wisefamily
CustomerThis 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 #11033Wes
ModeratorOk 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 #11043wisefamily
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 #11044wisefamily
CustomerHere’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 #11064Wes
ModeratorDid 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 #11066wisefamily
CustomerOkay, 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 #11073Wes
ModeratorI’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.
-
AuthorPosts
- You must be logged in to reply to this topic.