Forums

[resolved] Hooks Widgets (13 posts)

  1. cableghost
    Member
    Posted 2 years ago #

    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

  2. vtxyzzy
    Member
    Posted 2 years ago #

    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;
      ?>
  3. cableghost
    Member
    Posted 2 years ago #

    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.

  4. vtxyzzy
    Member
    Posted 2 years ago #

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

  5. PBP_Editor
    Member
    Posted 2 years ago #

    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 ?>
  6. Mark / t31os
    Moderator
    Posted 2 years ago #

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

  7. PBP_Editor
    Member
    Posted 2 years ago #

    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."

  8. Mark / t31os
    Moderator
    Posted 2 years ago #

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

  9. vtxyzzy
    Member
    Posted 2 years ago #

    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');
    ?>
  10. cableghost
    Member
    Posted 2 years ago #

    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

  11. vtxyzzy
    Member
    Posted 2 years ago #

    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);

  12. cableghost
    Member
    Posted 2 years ago #

    Perfect y'all, that worked.

    -Scott

  13. vtxyzzy
    Member
    Posted 2 years ago #

    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).

Topic Closed

This topic has been closed to new replies.

About this Topic