WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom sidebar on posts in a particular category + 1 more sidebar ??? (8 posts)

  1. sparklogix
    Member
    Posted 2 years ago #

    I'm trying to add a custom sidebar to a custom page template. The custom sidebar shows up, but so does the regular sidebar. I don't even have a function calling the sidebar in the custom page template so why is it there? Here is the page in question and this is the code from that page:

    <?php if(function_exists('wp_page_numbers')) : wp_page_numbers(); endif; ?>
    
              </div>
    
              <br class="clear" />
    
            </div>
    
    </div>
    
    		<div id="primary">
            <div class="add-box"><?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('obit-sidebar-ad-1')){} ?> </div>
    
            <div class="add-box-2"> <?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('obit-sidebar-ad-2')){} ?> </div>
    
            <div class="add-box"> <?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('obit-sidebar-ad-3')){} ?> </div>
          </div>
    
    <?php get_footer(); ?>

    My other question is, I also need these custom "obit" sidebars on all posts in the obituary category, as opposed to the sidebars on the rest of the site. How do I accomplish this?

    Thanks!

  2. Instead of creating another template for this, you could use conditionals.

    Take your regular page template - usually page.php.

    Replace your get_sidebar() function with something like:

    <?php if ( is_page('obits') || in_category('NN') ): ?>
    
    <div id="primary">
            <div class="add-box"><?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('obit-sidebar-ad-1')){} ?> </div>
    
            <div class="add-box-2"> <?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('obit-sidebar-ad-2')){} ?> </div>
    
            <div class="add-box"> <?php if(function_exists('dynamic_sidebar') && dynamic_sidebar('obit-sidebar-ad-3')){} ?> </div>
          </div>
    
    <?php else: 
    
    get_sidebar();
    
    endif; ?>

    You may need to make adjustments:

    - replace NN with the category ID of your obits category.
    - if your regular sidebar file is not named sidebar.php you'll need to modify the get_sidebar() function.
    - you may need to move your "primary" div code depending how your sidebar.php is coded

    More about conditionals:

    http://codex.wordpress.org/Conditional_Tags

    http://www.slideshare.net/zoonini/take-control-of-your-templates-with-wordpress-conditionals-8546925

    Let me know if you have further questions.

  3. sparklogix
    Member
    Posted 2 years ago #

    Yeah, I did that, the problem is that even with conditional statements, the regular sidebar.php file was being called, even though there was nothing calling that function. I still haven't found a real fix, just a pretty horrid hack that's not even worth mentioning because it sucks.

  4. Could I see your complete page.php code with the conditionals (put it in a Pastebin) as well as a link to the page in question on the site, where you're seeing the duplicate sidebar? The earlier link gives a 404.

  5. sparklogix
    Member
    Posted 2 years ago #

    Yeah, sorry, I had to change the link to make it live with my crummy fix. New link is here.

    My "fix" consisted of changing the function in the sidebar.php file from

    'if ( ! dynamic_sidebar( 'primary-widget-area' ) ) : ?>'
    to
    'if ( ! dynamic_sidebar() ) : ?>'

    Then I used the Per Page Sidebar plugin and replaced the sidebar in question. The default sidebar still showed up until I placed an empty text widget in the PPS.

    This is the code for the template page:
    http://pastebin.com/226z3JpZ

    Thanks so much for taking the time to help me out with this.

  6. sparklogix
    Member
    Posted 2 years ago #

    Oh, I don't have conditionals on this page, since I'm using a template. I forgot to mention that.

  7. Sorry for the delay in getting back to this.

    I didn't realize you also had a plug-in in use.

    So... just to be clear. Is anything not working correctly right now? I'm not totally sure what I'm looking for since you're not using the conditionals method I suggested earlier. Thanks!

  8. sparklogix
    Member
    Posted 2 years ago #

    So, I think I was making this far more complicated than it needed to be. I just did this and it worked perfectly: link

    In the single_obit.php file, I put in the custom sidebar I wanted for the obit posts. Thank you so much for trying to understand my gibberish and help me out.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.