How To Add Related Post In Wordpress

6 years ago

Follow the instruction properly then u get the coding right

log into your cPanel > File manager so
as to edit the core single.php file of your carrington theme.

1. Login to cPanel > Filemanger then follow the path public_html/your site name/wp-content/themes/carrington-mobile-1.2.

2. In this directory, you’ll see all the theme files, right click on the single.php file and click on Edit.

3. Once the page loads to edit,
Search using CTRL F for

cfct_content();

and in the line after the code
paste the below code.

PHP Code:


<?php 

?>
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags wp_get_post_tags($post-
>
ID);
if (
$tags) {
echo 
'Related Posts';
$first_tag $tags[0]->term_id$args=array(
'tag__in' => array($first_tag),
'post__not_in' => array($post-
>
ID),
'showposts'=>5,
'caller_get_posts'=>);
$my_query = new WP_Query
($args);
if( 
$my_query->have_posts() ) {
while (
$my_query->have_posts()) :
$my_query->the_post(); ?> <p><a href="<?php
the_permalink
() ?>"
rel="bookmark" title="Permanent
Link to <?php the_title_attribute
(); ?>"><?php the_title(); ?></
a></p> <?php
endwhile;
}
}
?> ?>

4. Then Click on Save at the top
right corner of the screen.
Copy with quote.
Drop any problem you encounter here.

Related forums
Forum

Ini Edo Flaunts Her Curves In Latest Post On Social Media

2 weeks ago
Forum

I Have Shown I Can Add Something To Man United – Van de Beek

2 weeks ago
Forum

#EndSARS: ‘This Is Not The Time To Post Beautiful Photos & Videos’ – Tacha

1 month ago
Forum

“You Must Post Laycon’s Picture On Your Page For Your Healing To Be Complete” – Samklef To Erica

2 months ago