get dynamic sidebar


#1

hi guys is there any way to get the dynamic sidebar instead of directly echoing it.

i want something like get_dynamic_sidebar(‘sidebar’)


#2

What do you want to do with it?!


#3
if(!function_exists('get_dynamic_sidebar'){
function get_dynamic_sidebar($index = 1)
{
$sidebar_contents = "";
ob_start();
dynamic_sidebar($index);
$sidebar_contents = ob_get_clean();
return $sidebar_contents;
}
}

#4

There are a lot of way to do it. Just depends on what you are trying to accomplish.


#5
ZoomIt said
if(!function_exists('get_dynamic_sidebar'){
function get_dynamic_sidebar($index = 1)
{
$sidebar_contents = "";
ob_start();
dynamic_sidebar($index);
$sidebar_contents = ob_get_clean();
return $sidebar_contents;
}
}

thanks a lot man it works :slight_smile:


#6

May somebody finally tell me what this does? :smiley:


#7

@karmathemes

when we use dynamic_sidebar(‘sidebar’) function it simply display the sidebar.
however i wanted to rerturn the content of sidebar instead of displaying it so zoomit has given the perfect solution for that.


#8

Hm I’m not sure if I understand the difference but thanks!


#9

the difference between the two is same as

echo and return in PHP.

hope this makes sense :slight_smile:


#10

Ah! Thanks!


#11
atinder said

the difference between the two is same as

echo and return in PHP.

hope this makes sense :slight_smile:

I have to disagree. If you use echo instead of return in the shortcode api, the content returned by the shortcode will be placed at the begining on the page/post, regardless of where you place it in your text.


#12
duotive said
atinder said

the difference between the two is same as

echo and return in PHP.

hope this makes sense :slight_smile:

I have to disagree. If you use echo instead of return in the shortcode api, the content returned by the shortcode will be placed at the begining on the page/post, regardless of where you place it in your text.

agree with you. thats why i needed this function

in shortcode if i use dynamic_sidebar(‘sidebar’) it echos at the top of page.can’t return contents.

but if when i used the function given above i can return the contents in shortcode :slight_smile: