Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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':
- <img src="http://i.imgur.com/lZmzaTS.png" alt="" />
- 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:
- <img src="http://i.imgur.com/5Nwj3GK.png" alt="" />
- 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':
- <img src="http://i.imgur.com/c69zCwX.png" alt="" />
- <strong>Step 1: </strong>
- Create backup of theme.
- <strong>Step 2:</strong>
- 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>';`
- <strong>Step 3:</strong>
- 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>';`
- <strong>Step 4:</strong>
- 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>';
- }`
- <strong>Step 5:</strong>
- Save and close file.
- <strong>Step 6:</strong>
- 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
- );`
- <strong>Step 7:</strong>
- 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
- );`
- <strong>Step 8:</strong>
- 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
- );`
- <strong>Step 9:</strong>
- Save (in child theme /modules folder, in case you use child theme) and close file.
- <strong>Step 10:</strong>
- 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;
- }`
- <strong>Step 11:</strong>
- Save file and close.
- <strong>Step 12:</strong>
- 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>';`
- <strong>Step 13:</strong>
- 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>';`
- <strong>Step 14:</strong>
- Save and close file.
- <strong>Step 15: </strong>
- Upload all files to your host and we are done! :)
- Enjoy...
Advertisement
Add Comment
Please, Sign In to add comment