get_sidebar() question
-
Can
get_sidebar()be called more than once from a file? It seems to only work the first time and be completely ignored the second time it’s called. Do I need to add another command before the second call?
-
Apparently the internal
get_template()function (which is what the various get_* tags use) performs some protection against loading a template multiple times. To get around this useinclude()to load the sidebar the second time, like this:<?php include( TEMPLATEPATH . '/sidebar.php'); ?>(And no, I won’t ask why you need to include the sidebar twice…)
Thanks, I’ll give that a shot.
(I’m making a theme – needs two sidebars with different content, but it seemed like a good idea to keep all of it in one
sidebar.phpfile so it would be easy to find.)Two sidebars with different content? Sounds more like a three column theme.
You would be partially correct sir! Actually, this particular site template is looking like a cross between http://www.ifelse.co.uk/ and http://www.wp-blogger.com/blog/ (or http://www.atthe404.com). So it’ll be a 3-2 column theme in the end.
Splitting the templates up for 3 columns is tricky because they need to be amalgamated back again for two columns. Mine is using a very ugly bit of engineering. (Dont ask ) 🙂 But I would not think that calling the same one twice is going to be the best way forward. My 2 cents. Good luck. These 3/2 cols rock 🙂
Ah, I see, I guess this will not be as simple as get_sidebarA, get_sidebarB, etc. Good luck with and thank you for your valiant efforts. 🙂
get_sidebarC might do it. Two for 3 cols, One for 2 cols.
… and if the same sidebar had to be called twice, it could be as simple as sidebarA=sidebarC.
I think I am right in saying that get_ can only be used for a WP approved template name. The self made ones need include or require.
Superficially this appears easy by using a php conditional in sidebar. Is home etc.
BUT. There is a lot of additional markup that needs to be generated for 3 cols – clearer divs etc. That is where it is difficult to do it elegantly.Word of advice: Design your 3 column and 2 column markup first thinking carefully about how to elegently move from one to the other. Only when you’re comfortable with the markup should you start work on the php/wp tags.
Work from outside in.
See, that is why you people are the experts and I just have fun reading, dissecting and learning. 🙂
The way the site is laid out (or planned to be, more accurately) is so that the front page will be two columns for the duration of the latest post (shown in full), and then 3 columns underneath to show a couple of certain categories of links and excerpts from the most recent posts. Pretty much every other page will be 2 columns, lacking the two
divs that make up the two columns at the bottom of the page.http://www.digitalrights.ca is the address of the site. It’s in a VERY early stage right now, and ugly as hell, but it works (except that there is currently *only* the 2/3 column template, no 2 column pages yet). The CSS is very unorganized, and I did have to make a single concession to IE 5.x’s 3-pixel-jog bug, but it is otherwise entirely hack free.
Please feel free to let me know if I’m on the right track with this 🙂
Oh, it works in IE 4, 5, 5.5, and 6, and Firefox (so presumably all recent Gecko browsers). I haven’t tested Opera, and have no access right now to Linux or Mac boxes to test it on. The only existing issue that kills me is that the site isn’t centered in IE 4 or 5.x.
text-align: center in the body will center it in IE. Set text-align back to left in your wrapper to get straight again. The 3 px jog is caused by two floats going in the same direction if you float left and right it can be avoided (as can the hack).I can see enough of the blog to see how its going to be set up. Looks a cool template.
The topic ‘get_sidebar() question’ is closed to new replies.