Monday, November 23, 2020
Home Blogging How to Show Related Pages in WordPress

How to Show Related Pages in WordPress

Lately, one in every of our customers requested us if there was a solution to present related pages as a substitute of posts in WordPress. Beforehand, we confirmed you easy methods to present related posts in WordPress with or with out plugin. On this article, we’ll present you easy methods to present related pages in WordPress.

Displaying Related Pages in WordPress Utilizing Plugin

The simpler solution to show related pages in WordPress is by utilizing a plugin.

Very first thing you should do is set up and activate the But One other Related Posts Plugin (YARPP) plugin. After activation, you should go to Settings » YARPP to configure the plugin.

On the plugin’s settings web page, scroll all the way down to Show Choices on your web site part. Underneath Robotically Show possibility, you should examine ‘pages’ and depart posts and media unchecked. That’s all, it can save you your settings now and YARPP will begin displaying related pages beneath web page content material in your WordPress web site.

Please be aware that YARPP together with another WordPress plugins is blocked by some managed WordPress internet hosting suppliers resulting from its heavy database utilization. One other problem that you could be face is that YARPP can’t search database for textual content in case your MySQL storage engine is about to InnoDB.

Displaying Related Pages in WordPress With out Plugin

Earlier than we present you easy methods to show related pages with out utilizing a plugin, we wish you to check out our article on the distinction between Posts and Pages in WordPress.

Best solution to show related posts is by on the lookout for tags or classes. However since WordPress pages should not have tags or classes, we’ll first have to allow classes and tags for WordPress pages. To try this, all you should do is set up and activate, the Put up Tags and Classes for Pages plugin.

The plugin works out of the field, so there usually are not settings so that you can configure. Upon activation, it would merely allow tags and classes on your WordPress pages.

Now you should edit a few pages you assume are related to one another and add tags. For instance, if in case you have a web page about your organization and one other web page for firm’s historical past, you’ll be able to tag them each as about us.

After you have got added tags to some pages, the subsequent factor you should do is so as to add this code in your theme’s features.php file or a site-specific plugin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function ghg_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();
}

This code appears to be like for tags related to a web page after which runs a database question to fetch pages with the same tags. To show the listing of pages, you would want to edit your web page template. Mostly it’s web page.php or content-page.php file. Merely add this line of code the place you need related pages to look.

1
<?php ghg_related_pages(); ?>

This may show related pages on any WordPress web page. It won’t look very fairly at first, so you’ll need so as to add some CSS and elegance it to match your theme.

Observe: code in features.php are handled the identical as plugins.

You May Also Like : How to Display a User’s IP Address in WordPress

If you liked this article, make sure to hit the bell for getting our latest updates and share this article with your friends in every social media platforms.

1 COMMENT

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -

Most Popular

50 Best Online Jobs From Home For Students – Earn 20K PM

In latest years, the alternatives for online jobs from home for students have gained great reputation. This is as a result of many of the...

Best Answers to the Question “Why should you be hired for this Internship?”

What is the greatest approach to ace an internship interview? Especially for a more energizing who has by no means appeared for a job-related...

Does Instagram Notify You if Someone Screenshots Your Story?

When Snapchat first burst on the scene, there have been loads of individuals very completely happy concerning the prospect of sending pictures to people...

How to Change Background Color on Instagram Story

It's arduous for me to recollect Instagram earlier than the tales characteristic was launched — it is a simple possibility for sharing updates and...

Recent Comments