Hi guys,
I really wanted to show ‘related articles’ and ‘more from author’ on post page separately. I managed to do this with a little help of the support team. I’m sharing this, because I think it is a nice extra feature.
In the theme option panel you can enable/disable the ‘related article’ module which contains both ‘related articles’ and ‘more from author’. In my case I didn’t want to display ‘more from author’ on posts written by user ‘redactie’, because he is the redactor and 90% of my sites post are written by him. I just wanted to show ‘related articles’ on posts written by user ‘redactie’:

Because my website has a category called ‘expert blogs’ which contains posts that are written by doctors, I wanted to only display ‘more from author’ on posts (expert blogs) written by doctors:

All posts written by other users than ‘redactie’ and all posts with other categories than ‘expert blogs’ should still have displayed both ‘related articles’ and ‘more from author’:

Step 1:
Create backup of theme.
Step 2:
Open Newsmag/includes/shortcodes/td_related_posts.php and go to line 30:
$buffy .= '<h4 class="td-related-title">';
$buffy .= '<a>block_uid . '" href="#">' . __td('RELATED ARTICLES') . '</a>';
$buffy .= '<a>block_uid . '" href="#">' . __td('MORE FROM AUTHOR') . '</a>';
$buffy .= '</h4>';
Step 3:
Add $post_cat = get_the_category(); to store the category of the post which contains the ‘related article’ module. The code will be:
$post_cat = get_the_category();
$buffy .= '<h4 class="td-related-title">';
$buffy .= '<a>block_uid . '" href="#">' . __td('RELATED ARTICLES') . '</a>';
$buffy .= '<a>block_uid . '" href="#">' . __td('MORE FROM AUTHOR') . '</a>';
$buffy .= '</h4>';
Step 4:
Place
Related articles:
$buffy .= '<a>block_uid . '" href="#">' . __td('RELATED ARTICLES') . '</a>';
AND
More from author:
$buffy .= '<a>block_uid . '" href="#">' . __td('MORE FROM AUTHOR') . '</a>';
into conditions. In my case:
If author of post is ‘redactie’, only display ‘related articles’:
if (strtolower(get_the_author_meta('display_name', $this->post->post_author)) == 'redactie') {
$buffy .= '<a>block_uid . '" href="#">' . __td('RELATED ARTICLES') . '</a>';
}
If category of post is ‘expert blogs’, only display ‘more from author’:
elseif (strtolower($post_cat[0]->cat_name) == 'expert blogs') {
$buffy .= '<a>block_uid . '" href="#">' . __td('MORE FROM AUTHOR') . '</a>';
}
In all other cases, display as normal both ‘related articles’ and ‘more from author’:
else {
$buffy .= '<a>block_uid . '" href="#">' . __td('RELATED ARTICLES') . '</a>';
$buffy .= '<a>block_uid . '" href="#">' . __td('MORE FROM AUTHOR') . '</a>';
}
Step 5:
Save and close file.
Step 6:
Open Newsmag/includes/modules/td_module_single.php and go to line 731:
$td_block_args = array (
'limit' => $td_related_limit,
'ajax_pagination' => 'next_prev',
'live_filter' => $td_related_ajax_filter_type, //live atts - this is the default setting for this block
'td_ajax_filter_type' => 'td_custom_related', //this filter type can overwrite the live filter @see
'class' => $td_related_class
);
Step 7:
Add $post_cat = get_the_category(); to store the category of the post which contains the ‘related article’ module. The code will be:
$post_cat = get_the_category();
$td_block_args = array (
'limit' => $td_related_limit,
'ajax_pagination' => 'next_prev',
'live_filter' => $td_related_ajax_filter_type, //live atts - this is the default setting for this block
'td_ajax_filter_type' => 'td_custom_related', //this filter type can overwrite the live filter @see
'class' => $td_related_class
);
Step 8:
Add condition to display ‘expert blogs’ posts by default when only ‘more from author’ is displayed. If you don’t add this condition, ‘related articles’ posts will be displayed by default and you will have to press ‘MORE FROM AUTHOR’ switch manually to load the relevant posts:
if ((strtolower($post_cat[0]->cat_name)) == 'expert blogs') {
$td_related_ajax_filter_type = 'cur_post_same_author';
}
So in case the posts have ‘expert blogs’ as their category, variable $td_related_ajax_filter_type will be ‘cur_post_same_author’ and the live filter will display ‘more from author’ posts.
Complete code will be:
$post_cat = get_the_category();
if ((strtolower($post_cat[0]->cat_name)) == 'expert blogs') {
$td_related_ajax_filter_type = 'cur_post_same_author';
}
$td_block_args = array (
'limit' => $td_related_limit,
'ajax_pagination' => 'next_prev',
'live_filter' => $td_related_ajax_filter_type, //live atts - this is the default setting for this block
'td_ajax_filter_type' => 'td_custom_related', //this filter type can overwrite the live filter @see
'class' => $td_related_class
);
Step 9:
Save (in child theme /modules folder, in case you use child theme) and close file.
Step 10:
Open style.css (in child theme folder, in case you use child theme) and add following code to fix the corners of the module title background:
.td-related-title .single-item {
border-radius: 3px;
}
Step 11:
Save file and close.
Step 12:
Reopen Newsmag/includes/shortcodes/td_related_posts.php and go to line 33 and add single-item after class="td-related-left td-cur-simple-item
So it will be:
$buffy .= '<a>block_uid . '" href="#">' . __td('RELATED ARTICLES') . '</a>';
Step 13:
Go to line 36 and add td-cur-simple-item single-item after class="td-related-right
So it will be:
$buffy .= '<a>block_uid . '" href="#">' . __td('MORE FROM AUTHOR') . '</a>';
Step 14:
Save and close file.
Step 15:
Upload all files to your host and we are done! 🙂
Enjoy…
-
This topic was modified 11 years by
Lucian.
Hi,
Thanks for sharing this! I have edited your post and should be showing it right now!
Please let me know if this still isn’t showing parts of your code and use http://pastebin.com/ for it.
Thanks
Hi,
The content of the post is: – http://pastebin.com/e4BuhSbP
Try to correct it and get it back to us and we’ll replace the current one.
Thank you, Emil G.
