• Resolved wen.wainwright

    (@wenwainwright)


    [Moderator Note: Topic title modified. When you start a new topic, use a good topic title.]

    First of all I posted this in a lower level area and I apologize for re-posting it. I would delete it if I could.

    I’m using TwentyThirteen and I want to use the optional right hand sidebar on my pages that are “posts.” I want to exclude the right hand sidebar for pages that are pages. In the page.php file the <?php get_sidebar(); ?> is located after the content because the main sidebar is just above the footer. There is no other call for the optional sidebar in this template. I figure I could use a custom page.php for the pages so it won’t show the right-hand sidebar but I do not know how to write php to unregister or not_get, etc., or where to put it. Again, sorry about the reposting of this question.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Thread Starter wen.wainwright

    (@wenwainwright)

    I’ve put this into a custom page template.php file just before
    </div><!-- .entry-content -->

    <div class="sidebar-2">
    <?php
    if( is_portfolio-page.php();
    $exclude = array("sidebar-2");
    ?>
    </div>

    It hasn’t broken the site which is good…but it isn’t working either. So I still need help!

    Thread Starter wen.wainwright

    (@wenwainwright)

    I moved that snippet of code above (prior post) to before the loop which also doesn’t break it or work.

    Thread Starter wen.wainwright

    (@wenwainwright)

    This is where I am now…(have I mentioned I don’t actually know any php?):

    /**
    968	 * Whether a sidebar is in use.
    969	 *
    970	 * @since 2.8
    971	 *
    972	 * @param mixed $index Sidebar name, id or number to check.
    973	 * @return bool true if the sidebar is in use, false otherwise.
    974	 */
    975	function is_active_sidebar( $index ) {
    976	        $index = ( is_int($index) ) ? "sidebar-$index" : sanitize_title($index);
    977	        $sidebars_widgets = wp_get_sidebars_widgets();
    978	        $is_active_sidebar = ! empty( $sidebars_widgets[$index] );
    979	        return $is_active_sidebar;
    980	}

    can I exclude it from a custom template page even though it IS active elsewhere?

    Thread Starter wen.wainwright

    (@wenwainwright)

    That last sentence above should not be a link. The link is from where I found that code before that last sentence.

    Moderator bcworkz

    (@bcworkz)

    Before you start altering theme files, you should create a child theme. This way your changes are preserved when the them is updated.

    If you do not want a sidebar on any page, simply remove the entire <?php get_sidebar(); ?> line from the page.php of your child theme. If you need it on some pages and not others, you could create a custom page template without the get_sidebar() call. Specify that template for any pages created that should not have a sidebar and the default for those that do.

    It’s also possible to encode the decision to use a sidebar or not so the same template can be used for everything. Precisely encoding what those conditions are can be tricky though, depending on how the decision is actually made.

    Thread Starter wen.wainwright

    (@wenwainwright)

    I am using a child theme. The <?php get_sidebar(); ?> is only located between the end of “content” and the get_footer. That refers to the main sidebar which is just above the footer. If I delete that it will get rid of the sidebar above the footer that I do want. There is an optional right hand sidebar that only displays if you put content in it. I have content in it so it displays the sidebar on all posts and pages. Since the only get_sidebar I can find on the various files is located after the content area I assume that get_sidebar refers to the sidebar above the footer and not to the optional right hand sidebar. I’ve looked through the different page templates and can’t find a call for the optional if being used right hand sidebar.

    Moderator bcworkz

    (@bcworkz)

    Ah! Thanks for explaining further, I apologize for not paying adequate attention earlier. There is another sidebar call in footer.php. Even though it is in the footer template, the sidebar could appear anywhere on the page with CSS, so do not discount it’s potential because of it’s location.

    get_sidebar() actually only loads a template file. In the case of the footer sidebar, sidebar-main.php is loaded. In that template, the call to dynamic_sidebar() is what actually displays the widgets.

    I assume you want to display this under some conditions, otherwise you would have simply removed the widgets. Either the call to load the template or to actually display the widgets would need to be placed inside a conditional so it is only called under those conditions. As mentioned earlier, defining those conditions might be tricky.

    Thread Starter wen.wainwright

    (@wenwainwright)

    Ok! I was definitely not envisioning the whole sidebars/templates/hierarchy thing like that. I want two headers, one for the “blog” pages and another for the “portfolio” pages. I need to either make this happen soon or just have two sites, one as a sub-domain. In the meantime everything I’ve ever known seems to have fallen out of my head. I’ll go look at those get_sidebar() calls again and see if I can break it in a way that shows the connection ??

    Thread Starter wen.wainwright

    (@wenwainwright)

    Alright, I took out that get_sidebar and it does get rid of the right hand sidebar, yay! I just made a custom page and took that one call out. It doesn’t solve the header image issue, but it’s a start.

    Moderator bcworkz

    (@bcworkz)

    When you say you want different headers, do you mean just different background images? Or other components as well, title, fonts, styling, etc.?

    You can selectively set the background image with the ‘theme_mod_header_image’ filter. If you want to have the theme appearance screens manage this it will take more work, but if you’re OK without using this feature it’s a simple matter to hardcode the alternate image. The initial appearance image selection can be applied to one or the other pages, it’s the additional image that’s the issue.

    In your filter callback you can determine which page type is being requested by checking the global $wp_query. I realize a lot of this is likely meaningless since you don’t know PHP. You can either pass this on to someone that does, or if you have any kind of programming aptitude, this is something you can probably figure out. Though it sounds like you’re on a deadline so there probably isn’t time for that.

    In that case do whatever is most expedient. Perhaps save this for later when you have some time.

    Thread Starter wen.wainwright

    (@wenwainwright)

    It’ll have to wait for now. I think everything I’ve ever known has now fallen out of my head. I’ll hang onto this though because I do want to get back to it later. Thanks so much for clarifying the first part as well, that definitely was a nice leap forward.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Customising a theme’ is closed to new replies.