I recently put up a guide on how you can install and use the carrington mobile theme for your wordpress blog, and I got a Facebook private message from someone requesting how he can easily customize and add up a related post widget to the mobile friendly design.
Just like any other wordpress theme, the file in charge of displaying posts in the Carrington theme is the single.php file and that’s where we would be adding the WP query that would output the related post widget.
Note: The related post we would be adding here is based on wordpress tags, meaning it relates articles you added tags to. If you don’t make use of the tags while posting in wordpress, this would not work for you.
Adding Related Post To Carrington Mobile
This would require you logging 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();” without the quotes and in the line after the code paste the below code.
?>
<?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'=>1
);
$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;
}
}
?>
<?php
4. Then Click on Save at the top right corner of the screen.
As I said earlier in this post, it would only work on sites where the tags are made use of.
Resource: How To Add Related Post To WordPress Without Plugins
20 Comments
Thank You Bro, Is cool and it is working for me
Hi SLimzeey,
Thanks a ton for letting us know it did work on your WordPress blog. Your comment is really appreciated, BTW, thanks for coming by.
I will go try it on my blog and i will let you know if it works fine on my blog. Thanks bro Oscar.
You are very much welcome pal, Thanks for dropping by.
Oscar your site is very informative
Thanks for the compliment. I do appreciate your comment down here.
its working, tanx
You are very much welcome Okhype.
Its not working for me… Any time I fix d code.. I get error
Hi Olamide,
What error do you get?
Plzz
Its not working here please help me out
Good morning oscar please I need your help , am using carrington mobile for the mobile version of my website, I want to know how to increase the amount of post displayed in home and other categories from 15 to 25 , just to increase the number of post displayed
Hi oscar , am using carrington mobile for the mobile version of my website ,please how can I increase the amount of post that is displayed on the home page and other categories, it only displaces 15 post and I want it to be 30 please help
My host doesn’t use an easy CP as such.. Can u pls tell me how to insert it through the theme editor??
It give me syntax error saying ‘unexpected T string bla bla’
Please help
how do i remove the featured image from this theme
Please I don’t know the actual place to paste the code am I going to replace this or placing it before or after or in bracket? put me through please
i love this post
Nice one oscarmini