You could try with the variable sidebar content example from the codex
http://codex.wordpress.org/Conditional_Tags#Variable_Sidebar_Content
The variable content is called from within the (same) sidebar.
This can help you too, conditional tags from within sidebar.php
http://seogadget.co.uk/rethink-that-sidebar-again/
I see several problems:
- is_page is for pages, not search results (search.php).
- Don’t echo php includes.
- searchform.php sounds like the search box form and not a sidebar.
I don’t know if $paged works with search results, but you could try something like this in search.php:
<?php if ($paged <= "1") { ?>
<?php include (TEMPLATEPATH . '/sidebar1.php'); ?>
<?php } else { ?>
<?php include (TEMPLATEPATH . '/sidebar2.php'); ?>
<?php } ?>
Thanks for informative answers, I am still trying with no joy however, so thought it might best to explain exactly what is needed.
I have 2 forms, 1 in my header and 1 on this page
The form on library page I want to display search results with searchform.php (which is a sidebar with a search form, just badly named, this is the current sidebar on library page)
I can make both appear with results, just not with a conditional statement that could decide which sidebar to display depending on the page.
I consider I have few options.
1. conditional statement in search.php to choose sidebar
2. conditional statement somewhere that activates search.php or searchtemplate.php depending on what form is used or what page is currently displayed.
Any suggestions, very much appreciated 🙂
cheers,
tom
<?php if ($paged <= “1”) { ?>
<?php include (TEMPLATEPATH . ‘/sidebar2.php’); ?>
<?php } else { ?>
<?php include (TEMPLATEPATH . ‘/sidebar1.php’); ?>
<?php } ?>
kind of works,(sidebar appears) but I dont know what ($paged <= “1”) refers too or how to make it specific to the library page, so I cant test it properly. I guess it means pages less than 1 ?
my library page id is 450, i hjave pages greater and less than.
I have also tried these…
<?php if (is_page(‘450’)) { ?>
or
<?php if (is_page(‘library’)) { ?>
or
<?php if (is_page_template(‘about.php’) ) { ?>
but these do not work for me either. Any suggestions, very much appreciated 🙂
cheers,
tom
My understanding is that the conditional statement should be in sidebar.php and not search.php
Sidebar.php is the one called by default, and that in turn calls either one of the two templates for the content.
I just tested this on my local copy and it worked.
Rename the two templates, to avoid confusion with the actual search form. Call them sidebar-library.php (the sidebar that appears only on the Image Library page), and sidebar-general.php (the one for all other pages), or something like that.
I am assuming that these templates have the content you want to display conditionally.
Then, on the default sidebar.php (not search.php) that came with your theme, try this
<?php
if(is_page('Image Library')) {
include(TEMPLATEPATH . '/sidebar-library.php');
}
else {
include(TEMPLATEPATH . '/sidebar-general.php');
} ?>
Hope this helps!
I use WordPress’ search.php to display search results, and I’ve never tried to display them on a Page. I don’t know if this can be done. You can put a search form on a page.
thanks buddha trance and iridiax,
buddha trance’s idea is a good one, I’ve tried already
sidebar.php
<?php
if(is_page(‘Image Library’)) {
include(TEMPLATEPATH . ‘/sidebar-library.php’);
}
else {
include(TEMPLATEPATH . ‘/sidebar-general.php’);
} ?>
Sidebar-general.php being the standard sidebar and sidebar-library being the sidebar that appears only on the Image Library page.
In Search.php I have gone back to <?php get_sidebar() ?> (but have also tried sidebar.php)
Anyway still no joy + i have to go to bed, will try again all day tomorrow I guess…
Many thanks for your help, great wishes,
tom