Show/Hide Author Box by Category? Code help needed and feature request, please!

Posted in: Newsmag
Post count: 6

I was very surprised that this theme doesn’t enable us to show/hide the author box (that appears at the bottom of single posts) by category, and that the only option the theme provides us is “all or nothing”; show/hide the author box across ALL posts in all categories. Really? May I please put in a strong feature request for this?

Meanwhile, I did research in the forums here and found some others who were similarly interested, however their desires were a little different from mine. Whereas most others want to only hide the author box for a category or two – I am the opposite, and would like to only SHOW the author box on one or two categories (the blogs, where it makes sense).

I used the theme panel to select the option to hide the author box, and then dove into the code on td_module_single_base.php and simply added

|| is_category( array( 65, 84 )) ) {

to line 705 that starts with
if (empty($hideAuthor)

So the line reads:
if (empty($hideAuthor) || is_category( array( 65, 84 )) ) {

I’ve tried placing this modified td_module_single_base.php in the (same subdirectories, etc.) in my child theme, and when that didn’t work, I tried overwriting the existing td_module_single_base.php file in the Newsmag theme itself, and it still doesn’t work.

Can anyone guide me on what I’m doing wrong or missing? Thanks so much in advance!

Post count: 6

Oops, I looked at this again and realized I am trying to change the wrong condition. I’ve asked the theme to hide the author box in the theme panel, but I’m adding my instruction to the code with the author box NOT hidden line. So, I added
if (td_util::get_option('tds_show_author_box') == 'hide' && is_category( array( 65, 84 )))

{
to line 706, so it looks like this:
if (empty($hideAuthor))
if (td_util::get_option('tds_show_author_box') == 'hide' && is_category( array( 65, 84 )))

{
and it still doesn’t work. * bangs head on desk *
I am not a PHP coder by any stretch, so if someone with more knowledge could point me in the right direction, I’d be grateful. I feel like I have the right idea but the execution is wrong.

Post count: 6

Just tried this and doesn’t work:
if (empty($hideAuthor) || td_util::get_option('tds_show_author_box') == 'hide' && is_category( array( 65, 84 )))

{

$buffy .= '<div class="author-box-wrap">';
$buffy .= '' ;
$buffy .= get_avatar(get_the_author_meta('email', $author_id), '96');
$buffy .= '
';
…. etc.

Post count: 6535

Hi
Thanks for the suggestion, I’ve added on our list and we will consider it for future updates. However we must carefully select what features we will include as we have over 250 features requests and the user always must get what is best from us. If more people will request this we will implement it.
You can achieve that by modifying the code, but with a different condition than the one you tried it. The is_category() function check if a category page is displayed not if a post belong to a specific category. To do that you need to use in_category().
So to display the author box only in some specific categories add this condition in td_module_single_base.php like here: http://screencast.com/t/Umqmoxdb8OIt

if (!in_category(array('50','51','56'))){
return;
}

This condition check if the post belongs to one of the specified categories and if the result is true will display the author box, otherwise returns.
Note that if post is included in more categories you need to add all categories ids on the list, otherwise the author box won’t be displayed or you can exclude it from the categories in which you don’t want to display the author box.

Hope this help.
Thanks!

Post count: 6

Hi Andrei,

Thank you! Your solution was much simpler and more elegant than my clumsy attempt. 🙂 However, I did have to remember to take the extra step of going back in to the Theme Panel again and ticking the ‘Show Author Box’ option there in order for this to work. I had turned that off, before. Now, it seems to be properly showing the author box on my ‘blog’ categories posts only.

Thanks again for your help, and for your quick response. I hope that there will be some way that Newsmag theme can one day soon enable us to do this from the theme options panel. Until then, thank you for the custom code I needed to do this.

Have a nice day!

Post count: 6535

Hi

Thanks you for your kind words. Glad I could help, we try our best to provide the best quality themes and support.
Thanks for the message!

Viewing 6 posts - 1 through 6 (of 6 total)
The forum ‘Newsmag’ is closed to new topics and replies.