• Resolved cableghost

    (@cableghost)


    I would like my theme to automatically insert a specific disclaimer in the post footer for posts in a certain category.

    I have a few themes that have built these hooks in as optional widgets, however, the theme I am using for this project does not have those widgets.

    Is there a generic hooks widget plug-in or an easy way to accomplish this? Note that my php skills are not great.

    -Scott

Viewing 12 replies - 1 through 12 (of 12 total)
  • I’m not certain that you can do exactly what you described. Usually the ‘blog’ page displays posts of all categories, so you could not have the disclaimer for only specific categories on such a page.

    However, if you are talking about an archive page, or a category-specific page, then you can do this.

    • Create a new footer.php file named footer-disclaimer.php with your disclaimer in it.
    • Change the template file to check for the category like this:

      change <?php get_footer(); ?> to:

      <?php
      if ( is_category('The Special Category') ) :
        get_footer('disclaimer');
      else :
        get_footer();
      endif;
      ?>
    Thread Starter cableghost

    (@cableghost)

    Thanks vtxyzzy

    I actually use a plug-in called Widget Context, where you can specify the category for which a widget should be shown. My problem is that I only have sidebars in this theme that accept widgets.

    When I say footer, I’m not referring to a page’s main footer, I am referring to the section after the content. Like what the Post Footer Plug-in does for posts. I suppose, I could hack that code and enter the disclaimer if/else statement.

    I am not familiar with the Post Footer Plugin, so I’m afraid I can’t help with that.

    You can just run a category conditional and place that after the
    <?php the_content(); ?>

    <?php if (in_category('id') ):
    	  // we're in Special Category ?>
    <p>This is where the disclaimer goes.</p>
    <?php endif; // end the if ?>

    Then it wouldn’t be in the footer, it would be inside the loop, which isn’t inside the footer.

    cableghost clarified that he is not referring to the footer of the page but the inline content of the post.

    cableghost “When I say footer, I’m not referring to a page’s main footer, I am referring to the section after the content. Like what the Post Footer Plug-in does for posts. I suppose, I could hack that code and enter the disclaimer if/else statement.”

    Yes indeed you are correct, and i do stand corrected… apologies for not reading more thoroughly before.. 😉

    As an alternative to modifying every loop, consider adding a filter by pasting code like this in your functions.php:

    <?php function mam_filter_content ($content) {
       if ( in_category('39') ) {
          $content .= '<div class="disclaimet">';
          $content .= 'Here is the text of the disclaimer';
          $content .= '</div>';
       }
       return $content;
    }
    add_filter('the_content','mam_filter_content');
    ?>
    Thread Starter cableghost

    (@cableghost)

    Thank you @vtxyzzy and @pbp_editor,

    Both of your options work. My disclaimer actually shows after a couple of other plug-ins, but it shows.

    Pic: http://9001links.info/files/disclaimer.jpg

    PS. how may I add multiple categories? I tried comma separated, but that does not appear to work.

    -Scott

    Use multiple categories like this:

    if ( in_category(array(44,16,32)) ) {

    You can control the order of the filters to some extent by using a priority. Most plugins will use the default of 10. You can have your filter execute first by using a lower priority:

    add_filter('the_content','mam_filter_content',9);

    Thread Starter cableghost

    (@cableghost)

    Perfect y’all, that worked.

    -Scott

    Glad it worked. Now, please use the dropdown at top right to mark this topic ‘Resolved’ (but you don’t need to post a new reply).

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Hooks Widgets’ is closed to new replies.