-->

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.

    Related Posts
    Related Posts

    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; ?>  				
    

    No comments