Genesis Themes

  • Home
  • Genesis Tutorials
  • WP Tutorial
  • Twenty Fifteen Theme
  • Social Media
  • WP Plugins

Display Related Posts by Tags in Genesis Theme

There are several ways we can add related posts in Genesis themes like with thumbnails,based on category and tags.Displaying related posts by tags is a not at all bad idea.Some might be use tags instead of categories.

Also see:

Show related posts with thumbnails in genesis theme.

Display related posts by category in genesis theme.

Step 1 :

Copy and paste the below listed code in your genesis child theme's functions.php

Go to Appearances > Editor > Functions.php.

Here's is the code to show related posts by WordPress tags in genesis.

/** Display related posts in Genesis based on Tags */

function related_posts_tags () {
if ( is_single ( ) ) {
global $post;
$count = 0;
$postIDs = array( $post->ID );
$related = '';
$tags = wp_get_post_tags( $post->ID );
foreach ( $tags as $tag ) {
$tagID[] = $tag->term_id;
}
$args = array(
'tag__in'               => $tagID,
'post__not_in'          => $postIDs,
'showposts'             => 5,
'ignore_sticky_posts'   => 1,
'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'
)
)
);
$tag_query = new WP_Query( $args );
if ( $tag_query->have_posts() ) {
while ( $tag_query->have_posts() ) {
$tag_query->the_post();
$related .= '<li><a href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to' . get_the_title() . '">' . get_the_title() . '</a></li>';
$postIDs[] = $post->ID;
$count++;
}
}
if ( $related ) {
printf( '<div><h3>Related Posts</h3><ul>%s</ul></div>', $related );
}
wp_reset_query();
}
}
add_action( 'genesis_after_post_content', 'related_posts_tags' );

Code explanation :

In above code,modify the number posts to display by changing the value in ‘showposts’ => 5

Step 2 :Style it in CSS file:

Here’s the code to add in your genesis child theme’s style.css file.

.related-posts {
margin: 10px 0;
}
.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;
}

Till now we covered 3 ways to display related posts based on category, tags and with thumbnails without using any plugins.If you face any problem while implementing the code, let us know using below comment box .

Related Posts

  • Genesis Display Posts from One Category on Home Page
  • Change Read More Text in Genesis
  • Move Genesis Navigation Menu Above Header
  • How to Display Category Description in Genesis Child Theme
  • How to Remove Post Meta in Genesis Theme
  • How to Unregister Layouts in Genesis
  • How to Modify Speak Your Mind in Genesis Theme
  • Genesis Exclude Posts in Specific Category from Home Page / Blog Page
  • Remove Website URL field from WordPress Comments in Genesis
  • How to Remove Post Date in Genesis Theme

Bluehost and Siteground Coupons for January 2016.

Best Premium WordPress Themes from TemplateMonster
download wordpress themes from MonsterOne

Categories

  • Blog
  • Blogger
  • Genesis Tutorials
  • Social Media
  • Top Websites
  • Twenty Fifteen WordPress Theme
  • WordPress Plugins
  • WordPress Tutorial