Any of you right here can show me how to make different sidebar per page?
Ps: no plugins.
Thanks,
Ara
Any of you right here can show me how to make different sidebar per page?
Ps: no plugins.
Thanks,
Ara
if ( is_page('archive') ) get_sidebar('archive');
if ( is_page('links') ) get_sidebar('links');
have a sidebar-archive.php, sidebar-links.php file in your theme directory.
This is just an example.
You still have to register the sidebar's in your functions.php and inside those sidebar.php files
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Links') ) : ?><?php endif; ?>
or !dynamic_sidebar('Archive') .. you get the idea...
inside your functions.php
if ( function_exists('register_sidebar') ) {
register_sidebar(array('name'=>'Links');
register_sidebar(array('name'=>'Archive');
}
That's one way, or if you just call the custom sidebar from within the template being used, then you don't need to register anything in your functions...
E.g. on archive.php, at the bottom where your sidebar call is, use:
~<?php get_sidebar('archive'); ?>~
It may mean a few extra template files instead of just allowing WP to use the index.php file (I use archive.php, archives.php, categories.php, etc) but then you don't have to remember to modify your functions every time you add a new custom sidebar.
Or, use ONE sidebar and conditional logic to display what you need for each view...? One file means one place to edit - that's what I like about using a single file.
Note, too, per Frumph's advice, that you *can* make an array of your logic
if (is_page('a') || is_page('b') || is_page('c')) {//do stuff here}
using additional elseif, else statments as necessary. Similar logic for category arrays can be found in the documentation...it's not the same as for pages.
The conditional logic concept for a sidebar is great way to go about doing something like that. And it's easy to manage, since you have one file called sidebar.php
Here's an example of something I used:
<?php if ( is_page('Section 1') || $post->post_parent == '1' ) { ?>
<p> Custom content for "Section 1"</p>
<?php } elseif ( is_page('Section 2') || $post->post_parent == '2') ) { ?>
<p> Custom content for "Section 2"</p>
<?php } else { ?>
<p> Generic sidebar content</p>
<?php } ?>
It checks the page name to see if it's the parent page for a section, or if it's a child of that parent page. I used it like this because I have custom content I wanted to display for different sections of my website.
If none of the statements match, it defaults to a generic set of sidebar content.
i am basically trying to do the same thing as a test for an upcoming project, but was testing using the footer.php.
i basically duplicated the footer.php file and called it test.php
then i went to the page.php and added this at the bottom
<?php get_test(); ?>
not working yet, so what else do I need to do to make the test.php content show on the page.php pages?
do I need to add or edit the functions.php? (or anything else)
sorry for hijacking this thread.
You must log in to post.