Different Sidebar for wordpress pages

Often one needs different sidebars for different pages in our wordpress coding. This can be implemented using the below mentioned code. The logic used here is that we get the post id and assign sidebar based on their page or post id's.

We have to adjust the below code in our wordpress sidebar.

global $id;
$post_id_current = get_post($id,ARRAY_A);
$post_parent = $post_id_current['post_parent'];
if($post_parent!='')
{
$my_id=$post_parent;
}
else
{
$my_id=$id;
} 

if($my_id!==4 )
{
 if ( !function_exists('dynamic_sidebar')

|| !dynamic_sidebar('sidebar2') ) : endif; 

}
else
{
 if ( !function_exists('dynamic_sidebar')

|| !dynamic_sidebar('sidebar1') ) :  endif; 
}

No comments:

Post a Comment