ThemeShaper Forums » Thematic

[closed]

Adding Content at Bottom of Content in One Category

(5 posts)
  • Started 10 years ago by nimrod
  • Latest reply from nimrod
  • This topic is resolved

Tags:

  1. nimrod
    Member

    I'm working with AutoFocus Pro and want to add Tweet button code at the bottom of each post ONLY in the Blog category.

    This way, only the blog posts get the Tweet button and all other AutoFocus image gallery posts throughout the rest of the site do not.
    _________

    I found this little code block that drops an hr at the bottom of posts, but I don't know how to limit it to JUST the Blog category:

    function divider($content)
    
    {
    $content .= "<hr class=\"divider\" />";
    return $content;
    }
    add_filter('the_content', 'divider', 0);

    _________

    Of course, the tweet button should appear at the bottom of Blog posts both on the Blog category page (with all Blog posts listed) and on the single Blog post pages.

    Posted 10 years ago #
  2. check the codex for any logic questions:
    http://codex.wordpress.org/Conditional_Tags

    function divider($content) {
    
    if (is_category('blue-cheese'))[
    $content .= "<hr class=\"divider\" />";
    return $content;
    }
    }
    add_filter('the_content', 'divider', 0);

    should limit the function only to posts in the blue-cheese category. is Blog a category for you or do you mean the regular blog (aka index) page. the conditional for that and single posts would be

    if( is_home() || is_single() )

    i dont know enough about autofocus to know what kind of post generates the image galleries to know how to exclude them. if they are a custom taxonomy then they won't trigger is_single as true

    Posted 10 years ago #
  3. nimrod
    Member

    Thanks for the informative response.

    AutoFocus simply uses a "Blog" category for blogging purposes to separate that type of post from the image gallery type posts it focuses on. It's not the home page or front page.

    So, my idea was to restrict the above content addition to this one "Blog" category.

    I notice, though, that adding the if (is_category()) code causes the content of the rest of the non-blog posts to disappear! There's simply no content in any other posts while all content is fine plus the hr divider in the Blog category.

    Is there some sort of "else" statement that might reset the content to show normally sans the hr divider on all other categories?

    Posted 10 years ago #
  4. yeah oops. if it isn't in the category you still have to return the content!

    function divider($content) {
    
    if (is_category('blue-cheese'))[
    $content .= "<hr class=\"divider\" />";
    return $content;
    } else {
    return $content;
    }
    add_filter('the_content', 'divider', 0)
    ;

    hope that helps

    Posted 10 years ago #
  5. nimrod
    Member

    Yes! This seems to work.

    However, there are a couple syntax errors. There was a "[" which should be "{" at end of line 3 and a missing closing "}" before the "add_filter" at line 9.

    Here is the final working function:

    function divider($content) {
    
    if (is_category('blue-cheese')){
    $content .= "<hr class=\"divider\" />";
    return $content;
    } else {
    return $content;
    }
    }
    add_filter('the_content', 'divider', 0);
    Posted 10 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.