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.

adding related post to carrington mobile theme

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

  1. 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

  2. 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

  3. 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

LEAVE A REPLY

Please enter your comment!
Please enter your name here