Different sidebars for different pages on Wordpress - wordpress-theming

I'm trying to design a theme on WordPress (version 3.3.2) but I am having a few problems in having the sidebar display a different set of widgets on certain pages.
I have tried several online tutorials and this one in particular http://www.rvoodoo.com/projects/wordpress/wordpress-tip-different-sidebars-on-different-pages/ but unfortunately there is no change in the sidebar when I move to a different page
I registered two sidebars on my functions.php as shown below, one which I would consider as main, and the other as a custom sidebar, and I also added different widgets to these sidebars.
<?php register_sidebar( //register sidebar
array(
'name' => 'Right-side',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
register_sidebar( //register second sidebar
array(
'name' => 'Second-right',
'before_widget' => '<div class="rightwidget">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>',
));
?>
Following that, I created the files sidebar.php and sidebar-second.php to be able to call them.
sidebar.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Right-side')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
sidebar-second.php
<div id="sidebar">
<?php if (!function_exists('dynamic_sidebar') || !dynamic_sidebar('Second-right')) : ?>
<h3 class="widget-title">No widget added</h3>
<p> Please add some widgets</p>
<?php endif; ?>
</div><!--ends sidebar-->
And then I added replace my <?php get_sidebar() ; ?> statement with following conditional
<?php if( is_page('225') ) : ?>
<?php dynamic_sidebar('second'); ?>
<?php else : ?>
<?php get_sidebar() ; ?>
<?php endif ; ?>
However only the widgets added to the sidebar.php are displayed on every page. Any help on how I could change this, or pointers on what I could be doing wrong. Thanks.

I looks like you are using <?php dynamic_sidebar('second'); ?> where you should be using <?php get-sidebar('second'); ?>
What get_sidebar('foo') does is look for a file named 'sidebar-foo.php' in the root directory of your theme and includes it. dynamic_sidebar('bar'), on the other hand, looks for a sidebar registered with:
<?php register_sidebar( array( 'name' => 'bar' ... ) ) ?>
Hope this helps!

Why don't you use the Custom Sidebar Plugin?
It's really easy to use and does not need any coding

You have two sidebars. when you want to use the sidebar-second file on a particular page, instead of calling
<?php get_sidebar('second') ; ?>
TRY
<?php get_sidebar('sidebar-second.php') ; ?>
this should do the trick

Related

Sidebar Content Box not editable

I have built a custom theme for a client some 12 months ago and all was working fine until recently. My client is unable to edit the content in the widgets on his sidebar.
I have tried to add other text widgets to the sidebar and even those are uneditable.
I disabled all the plugins to see if any of those are the culprit and as such made zero difference. Incidentally all of the text widgets are displaying perfectly on the public side of the website but my client is unable to add or edit and text widget in the sidebar.
Here is a screeny showing whats going on...
Many thanks for any advice you can give in this.
Phillip Dews
EDIT
For those that require it. Here is the code from my custom theme....
functions.php
function paradisereloaded_widgets_init() {
register_sidebar( array(
'name' => __( 'Sidebar', 'paradisereloaded' ),
'id' => 'sidebar-1',
'description' => __( 'Add widgets here to appear in your sidebar.', 'paradisereloaded' ),
'before_widget' => '<section id="%1$s" class="widget %2$s">',
'after_widget' => '</section>',
'before_title' => '<h2 class="widget-title">',
'after_title' => '</h2>',
));
}
add_action( 'widgets_init', 'paradisereloaded_widgets_init' );
And now the
sidebar.php
<?php
/**
* The template for the sidebar containing the main widget area
*
* #package WordPress
* #subpackage paradisereloaded
* #since Paradise Reloaded 1.0.0
*/
?>
<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
<aside id="secondary" class="sidebar widget-area" role="complementary">
<?php dynamic_sidebar( 'sidebar-1' ); ?>
</aside><!-- .sidebar .widget-area -->
<?php endif; ?>

WordPress: Displaying whole template, not just the_content

I've got a single page website with a front-page.php that shall include all my custom templates (each one is a static page).
<?php get_header();
$args = array(
'sort_order' => 'ASC',
'sort_column' => 'menu_order',
'post_type' => 'page',
'post_status' => 'publish'
);
$pages = get_pages($args);
foreach ($pages as $page_data) {
$content = apply_filters('the_content', $page_data->post_content);
?>
<?php echo "$content" ?>
<?php
}
get_footer();
?>
With "the_content" it references only the content of my text in the backend, but not all my tags surrounding my the_content tag in the template itself, for example:
<?
/*
Template Name: Features
*/
the_post()
?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<section>
<? the_content() ?>
</section>
<?php endif; ?>
In this case, the surrounding tags section aren't selected and don't appear in the markup.
What do I have to change in my front-page.php to select the whole template, not only its template?
Thanks so much in advance!
You could put the loop part of each page template in a separate template part and call the parts dynamically on your front page with get_template_part:
foreach ( $pages as $page_data ) {
$template = get_post_meta( $page_data->ID, '_wp_page_template', true ); // get page template path
$template = substr( $template, 0, -4 ); // chop off .php from the string
get_template_part( 'loop', $template );
}
For a template 'Features' (filename features.php) it would look for loop-features.php, etc. Fallback will be loop.php.

Image Slider flashes wrong image at first

I am using a wordpress theme, Pitch Pro, and it has a built in slider. My issue is that sometimes the slider will flash the wrong image for a second. I noticed that it does not do it normally but only if I go from a page such as support to the home page. I have tried changed and setting the order. Changing the max amount of slides, currently 6, but nothing seems to fix it.
The site currently is jrummy16.com/test if anyone has any idea on a fix.
Not sure if this could relate to it anyway but the server I am using has issues and to fix it hostgator told me to add define( 'CONCATENATE_SCRIPTS', false ); to my config.php file. It fixed the issue but I do not recall the slider having this issue before adding that.
I have no idea on how to even start troubleshooting this. So any help would be greatly appreciated.
EDIT
All of the files were found inside the Theme, Pitch Pro.
I opened up my home.php file and I find this at the top for slider.
<?php
$slider_template = apply_filters('pitch_slider_template', array('slider', null));
get_template_part( $slider_template[0], $slider_template[1] );
?>
I then went and opened up slider.php in the same folder. It has this code,
<?php
$slides = new WP_Query(array(
'numberposts' => siteorigin_setting('slider_max_slides'),
'nopaging' => true,
'post_type' => 'slide',
'orderby' => 'menu_order',
'order' => 'ASC'
));
if($slides->have_posts()){
?>
<div id="slider">
<div class="container">
<div class="slides nivoSlider">
<?php while ($slides->have_posts()) : $slides->the_post(); if(has_post_thumbnail()) : ?>
<?php if(get_post_meta(get_the_ID(), 'slide_destination', true)) : $destination = get_post_meta(get_the_ID(), 'slide_destination', true) ?>
<?php echo '<a href="'.esc_url(get_permalink($destination)).'" title="'.esc_attr(get_the_title($destination)).'">' ?>
<?php elseif(get_post_meta(get_the_ID(), 'slide_destination_url', true)) : $destination = get_post_meta(get_the_ID(), 'slide_destination_url', true) ?>
<?php echo '<a href="'.esc_url($destination).'">' ?>
<?php endif; ?>
<?php echo get_the_post_thumbnail(get_the_ID(), 'slide') ?>
<?php if(!empty($destination)) echo '</a>' ?>
<?php endif; endwhile; ?>
</div>
<?php $slides->rewind_posts(); ?>
<div class="indicators-wrapper">
<ul class="indicators">
<?php while ($slides->have_posts()) : $slides->the_post(); if(has_post_thumbnail()) : ?>
<li class="indicator <?php if($slides->current_post == 0) echo 'active' ?> indicator-group-<?php echo $slides->post_count ?>">
<div class="indicator-container">
<div class="pointer"></div>
<h4><?php the_title() ?></h4>
<?php the_excerpt() ?>
</div>
</li>
<?php endif; endwhile; ?>
</ul>
</div>
</div>
</div>
<?php
wp_reset_postdata();
}
I am not sure if this will help or not but I hope that it does.
I think the reason is that before slider loads completely, the page will show last image in the list of slides and in your case it is this one:
<img width="705" height="344" src="http://jrummy16.com/test/wp-content/uploads/BA-slider.jpg" class="attachment-slide wp-post-image" alt="BA-slider">
Here is a similar problem and it has few of the solutions which you may use it as well.
UPDATE:
I found this article which suggests to modify your CSS. I would paste the code here but the article uses image to show CSS code:)

If statement not working when it really should

Okay, this is by far one of the strangest things I've come across in some time.. I have the following piece of code in one of my woocommerce files:
<?php $titlevar = wp_title('', 0); ?>
<?php echo $titlevar; ?>
<?php if($titlevar == "Men") { ?>
<div id="sidemenu" style="float:left;width: 180px;float:left;height:100px">
<?php wp_nav_menu( array('menu' => 'sidemenumen' )); ?>
</div>
<?php } ?>
As you can see, if my $titlevar variable equals "Men", it should display a div with a menu inside. I've echo'ed the variable at the top and it actually outputs 'Men' (without quotes of course), how is it possible that it's not showing my div??

Wordpress; image not appearing post loop

I have post about this before, but I didn't get any conclusive answer but I'm really hoping someone can help me. I have setup some custom post types, and with them, some custom fields using Wordpress 3's UI.
One of the fields I have set up is called banner_image, but in the loop, it doesn't output the image.
<?php echo get_post_meta($post->ID, 'banner_image', true); ?>
This simply outputs the ID number of the post. If I set the function to false, I get an array with this ID in and nothing else. How do I get the path to the image? I can't work this out and Googling reveals a sea of content not related to my problem, it's a real difficult one to search for so you're my only hope!
Many thanks,
Michael.
<?php
global $post;
$tmp_post = $post;
$args = array(
'post_status' => 'publish',
'post_type' => 'work',
'order' => 'DESC'
);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); ?>
<?php if( get_post_meta($post->ID, 'show_in_home_banner', true) == "yes" ) { ?>
<li class="slide">
<div class="slide-image">
<a href="<?php echo get_page_link($post->ID) ?>">
<?php echo get_post_meta($post->ID, 'banner_image', true); ?>
</a>
</div>
<div class="slide-content">
<h3 class="slide-header"><?php echo get_post_meta($post->ID, 'sub_title', true); ?></h3>
<p class="slide-title"><strong><?php echo the_title(); ?></strong></p>
</div>
</li>
<?php } ?>
<?php endforeach; ?>
Try this
<?php echo get_post_meta($post->ID, 'banner_image', $single); ?>
Apparently, the custom field 'banner_image' doesn't have the right value. I guess it doesn't save the correct value first. You may want to install the Simple WP FirePHP plugin (http://wordpress.org/extend/plugins/simple-wp-firephp/) and check the value with the fb() function.