Yellowed pages from a dictionary

How to Show Related Pages in WordPress With /Without Plugin

Some WordPress users asked” Is it possible to show related pages in WordPress? I can easily show related posts, but do not know how to show related pages.” So, in this article, I will walk you through two approaches to show related pages in WordPress.

 

1. Showing Related Pages With Plugin

 

To show related pages, a workable plugin is recommended here: Yet Another Related Posts Plugin. This plugin allows you to show related pages after proper configuration. This way is the easiest way to show related pages.

 

Needless to say, the first thing you need to do is to download and install this plugin. After activate the plugin, hit Setting to configure the plugin.

On the Setting page, the first two sections can be ignored, and you only need to scroll down to ‘Display Options for your website’ section. Under Automatically Display option, check the box before Pages and lever the boxed before Posts and Media blank. Then select to show related pages as a list or show pages’ thumbnails.

 


That’s all you need to do before you press Save Changes button. After you save the changes, this plugin will automatically show related pages on any WordPress pages in your site.

 

This plugin works fine and helpful, however, due to its large database usage, it is blocked by many managed WordPress hosting provider. So, if your site loading time is slower after activate this plugin, you’d better deactivate it and use the second method.

 

2. Showing Related Pages Without Plugin

 

To relate pages, the most efficient way is using tags and categories. However, WordPress do not have tags or categories for pages. So, before starting this process, we need to enable tags and categories to pages. To do so, a plugin Post Tags and Categories for Pages is needed.

 

You do not need to set otherwise after you download and activate this plugin. After activation, this plugin will automatically enable tags and categories for your WordPress pages.

 


Now, what you need to do is to add some tags to your pages that you want to be related.

 

Then, you need to add this code to your function.php

 

function wpb_related_pages() { $orig_post = $post; global $post; $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( 'post_type' => 'page', 'tag__in' => $tag_ids, 'post__not_in' => array($post->ID), 'posts_per_page'=>5 ); $my_query = new WP_Query( $args ); if( $my_query->have_posts() ) { echo '<div id="relatedpages"><h3>Related Pages</h3><ul>'; while( $my_query->have_posts() ) { $my_query->the_post(); ?> <li><div class="relatedthumb"><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_post_thumbnail('thumb'); ?></a></div> <div class="relatedcontent"> <h3><a href="<? the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3> <?php the_time('M j, Y') ?> </div> </li> <? } echo '</ul></div>'; } else { echo "No Related Pages Found:"; } } $post = $orig_post; wp_reset_query(); }

After adding this code, to display a list of related pages on your pages, you need to add another code to the page template (page.php):

 

<?php wpb_related_pages(); ?>

 

Add it to where you want the related pages show. You may need to add some CSS code to custom the Related Pages section for it does not look nice.

About the author: Magee