Display Related Posts Code Genesis Child Part 7 - Genesis Framework
You already know the importance of SEO On Page. One of the main reasons websites have a better ranking in search engines. Related articles help websites improve SEO On Page rankings.
Displaying a related article on Genesis Child themes is quite simple. Genesis uses hooks to customize and extend functionality from child themes.
Display Related Posts By Categories
Display related posts on Genesis Child themes starting with one action hook 'Genesis_entry_footer'. This hook is located on all posts, pages, categories so to display properly on the article page we add conditions is_single. The code below must be copied and copied into the file function.php your child theme.
// Select posts in the same categories as the current post. if ( ! function_exists( 'related_post_category' ) ): add_action( 'genesis_entry_footer', 'related_post_category', 40 ); function related_post_category() { if ( is_single ( ) ) { // Get a list of the current post's categories global $post; $categories = get_the_category($post->ID); if ($categories) { $category_ids = array(); foreach($categories as $individual_category) $category_ids() = $individual_category->term_id; $args=array( 'category__in' => $category_ids, 'post__not_in' => array($post->ID), // Ensure that the current post is not displayed 'posts_per_page' => 3, // Number of related posts to display 'orderby' => 'rand', // Randomize the results ); $my_query = new wp_query($args); if( $my_query->have_posts() ): $i = 0; ?>
have_posts()):$my_query->the_post(); ?>
Display Related Posts By Tags
As above, the code below must be copied and copied into the file function.php your child theme.
// Select posts in the same tags as the current post. if ( ! function_exists( 'related_post_tags' ) ): add_action( 'genesis_entry_footer', 'related_post_tags', 40 ); function related_post_tags() { if ( is_single ( ) ) { global $post; // Get a list of the current post's tags. $tags = wp_get_post_tags($post->ID); if ($tags) { $tag_ids = array(); foreach($tags as $individual_tag) $tag_ids() = $individual_tag->term_id; $args=array( 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), // Ensure that the current post is not displayed 'posts_per_page' => 3, // Number of related posts to display 'orderby' => 'rand', // Randomize the results ); $my_query = new wp_query($args); if( $my_query->have_posts() ): $i = 0; ?>
have_posts()):$my_query->the_post(); ?>
Conducting the css code
Each person has a different aesthetic perspective this article I will code css so you have a rough overview. To be content you can write your way. Copy css and pate it into file style.css your.