How To Add Related Post In Wordpress

Forum 9 years ago

How To Add Related Post In Wordpress

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.

What's your rating?
0
{{ratingsCount}} Votes


Related forums
Your Post Broke My Heart - Opeyemi Aiyeola Writes to Jamiu Azeez
Forum | 6 days ago

Your Post Broke My Heart - Opeyemi Aiyeola Writes to Jamiu Azeez

“How much is Wizkid?, add Burna Boy” – Fan brags Davido could buy Wizkid, Burna Boy after ₦102 billion jet purchase
Forum | 1 week ago

“How much is Wizkid?, add Burna Boy” – Fan brags Davido could buy Wizkid, Burna Boy after ₦102 billion jet purchase

How a Blog’s Post Damaged My Self-Esteem – Beverly Naya
Forum | 3 weeks ago

How a Blog’s Post Damaged My Self-Esteem – Beverly Naya

St. Gerad
Forum | 1 month ago

St. Gerad's Catholic Hospital, Kaduna Basic Nursing, Midwifery & Post Basic Nursing forms, 2024