Homepage › Community Forums › Epik Theme Support › How To Build Your Own Related Posts Plugin On Epik
Tagged: related posts
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?
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
Eric,
Thank you for replying. Where can I send you the link?
Not sure if I want to post it here.
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
I did the Private Reply box. Has anybody seen it yet? It’s reply #10898
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.
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' );
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.
/** 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' );
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.
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.
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.
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.