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.
I am going just about nuts.
I am making a custom theme. I have created two sidebars one will be for the front page and the other for the blog itself.
I have created a function:
if ( function_exists('register_sidebar') ){
register_sidebars(array(
'name' => 'blog',
'before_widget' => '<div class="sidebar-item">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>', ));
register_sidebars(array(
'name' => 'front',
'before_widget' => '<div class="sidebar-item">',
'after_widget' => '</div>',
'before_title' => '<h2>',
'after_title' => '</h2>', ));
}
Inside the sidebars I added their names:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('blog') ) : ?>
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('front') ) : ?>
and i added the names in the index.php and the front.php (respectively). The sidebars do show up in the widget settings and on the site. However the only thing I can see is the default sidebar(s) settings. As if I didn't add any widgets.
Seriously it's almost two in the morning and I've been working for the last twelve hours non-stop. This is the only thing that is killing my work.
Please tell me what I am doing wrong.
Why not do a normal widgitized sidebar and then use Widget Logic to handle it? http://wordpress.org/extend/plugins/widget-logic/
thanks , but I ended up fixing the issue. I wanted to be able to use the code rather than a plugin. That one does look interesting though.
Keep in mind that if your sidebar(s) is/are not registered in functions.php you can't use widgets.
Hi all, I am new to wordpress and am experimenting with the "Hamasaki" theme, it comes with 4 ads in the sidebar which I made into 6---also, other than the Home page(index) I have 5 Parent categories. I do not use google adsense or anything like that, my question, is it possible to have display different ads in the different categories? now the ones on the homepage display throughout the page. I tried to work with the sidebar.php but cannot seem to nail it. My ads will consist of a jpg in my images folder with a link to the advertisers site. Would appreciate any help I can get.
Thank you
Sure it's possible. You can use Conditional Tags so that on a certain page a given variation of the sidebar is displayed.
Thank you SS_Minnow, let me see if I am new to wordpress, let me see if I can figure out the Conditional Tags
If you wanted to have a different sidebar on a page called "Blog" than what you have on your other pages, you would put this into the page.php file where it calls in the sidebar:
<?php if ( is_page('blog') ) { ?>
<?php include(TEMPLATEPATH.'/sidebar2.php');?>
<?php } else { ?>
<?php include(TEMPLATEPATH.'/sidebar.php');?>
<?php } ?>
If the sidebar is registered in functions.php the code can be done differently but you can find that code by searching the forum & codex.
I share the same problem, I want to have different sidebars to different pages? from what I can understand the problem has been solved. The things is that programming is not one of my strenghts, so I would like it if someone explained it to me as if you were explaining it to an infant ;)
Hi
I have a unique message in my sidebar for each page. For example:
<div class="intro">
<?php if (is_page('home')) { ?> <?php $post_id = 11;
$queried_post = get_post($post_id); echo $queried_post->post_content;?> <?php } ?>
But how do I make one for each of my archives? How can I reference them instead of (in this example) "home".
Thanks
James
Hi,
Very tricky solution. It will be better to combine all the methods or at least better one into one plugin. So other users can use them.
Thanks
If somebody does it please put a link here for reference.
You could do something similar to this (just the general idea, you'll have to check the actual code):
<?php
if($sidebar_name = get_post_meta($post->ID, 'sidebar', true)){
dynamic_sidebar($sidebar_name);
}
?>
Then you need to add the following to functions.php:
<?php
// Activate the widget based sidebar
if(function_exists('register_sidebar')){
register_sidebar(array('name'=>'Default'));
foreach(get_custom_sidebars() as $sb){
register_sidebar(array('name'=>$sb[meta_value]));
}
}
function get_custom_sidebars(){
global $wpdb;
$query = "SELECT * FROM $wpdb->postmeta WHERE meta_key = 'Sidebar' GROUP BY meta_value";
$sidebars = $wpdb->get_results($query, ARRAY_A);
return $sidebars;
}
?>
Hopefully this helps.
May I recommend the plugin Core Sidebars?
@Frumph -
I am trying to do a similar thing, but with post pages under one category. So, only posts under a specific category will get unique sidebar.
I am running "The Station," a theme from Woothemes, and it is giving me some code that you mentioned above in the sidebar.php file:
<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Links') ) : ?><?php endif; ?>
I don't know how to use this syntax within an "if/else" statement because of the colon toward the end. I want it to basically use the existing sidebars built into the theme; however use an "if" statement to point to a different sidebar for one particular category.
I have already tried to make this change within the single.php file, but for some reason it doesn't work. It shows the new sidebar, but doesn't seem to take much notice of the "if/else" statement, so it shows that sidebar for everything - including posts which do not fall under that category.
Any thoughts?
Thanks
This an answer for JT101 -
James, I figured this out for a recent project - You just need to take archive.php (singular, not plural), and duplicate, and give it the name category-17.php (or whatever the cat ID is).
Customize that page as you'd like. Then, in that page, when you call the sidebar, put the call like this:
<?php get_sidebar('cat17'); ?>
You'll now have to create a custom sidebar:
sidebar-cat17.php
Now, this is the trick that makes the sidebar come up consistently throughout all posts in the category; you'll need to go into single.php, and put this logic:
<?php
//to be able to use this outside the_Loop
if ( have_posts() ) { the_post(); rewind_posts(); }
if ( in_category('17') ) {
get_sidebar('cat17');
//gets sidebar-cat17.php
} elseif ( in_category('75') ) {
get_sidebar('cat75');
//gets sidebar-cat75.php
//repeat as necessary
} else {
get_sidebar();
//gets sidebar.php
}
?>
Other conditional statements only call the sidebar for the category page, not for any of the post child pages.
Widget logic plugin. The best new-to-me way to do this, and I've seriously tried just about everything. More than what has been mentioned here I know that.
http://wordpress.org/extend/plugins/widget-logic/
Adds an input to each sidebar widget that you can do is_page(), is_single() etc. Pretty nifty :)
This topic has been closed to new replies.