Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

My pages have a sidebar with too many widgets, and it looks bad when the content is short and the sidebar is too long.

I want to randomize the widgets I'm showing in the sidebar. Meaning I will add all the potential widgets to the sidebar, and it will randomly only display a few.

I would also like some control over this, for example to have a few widgets always appear, and only the rest randomized.

I tried finding relevant plugins, but the only ones I found just randomized images or posts.. never different types of widgets.

share|improve this question
    
It could be easier to register multiple widget areas and randomize these instead. Does it make sense? Let me know if you are interested in such solution and I will outline the code needed to achieve it. –  Michal Mau Dec 11 '11 at 14:30
    
so why not attempt this solution: 1) create an extra widget area for each randomly appearing widget and place it inside this area. 2) create a special widget that receives as arguments the widget areas I want to randomize and this special widget will display one of them randomly. makes sense? this way I'll have easy control of which widgets are randomized and which are not –  talkol Dec 11 '11 at 15:30
add comment

2 Answers 2

up vote 1 down vote accepted

Here comes the workaround solution discussed in the comments:

functions.php:

add_action( 'widgets_init', 'talfluxive_register_sidebars' );
function talfluxive_register_sidebars() {
    // register five random widget areas
    register_sidebars( 5, array( 'name' => 'Random Widget Area %d' ) );
    // register two fixed widget areas
    register_sidebars( 2, array( 'name' => 'Fixed Widget Area %d' ) );
}

sidebar.php

dynamic_sidebar( 'Fixed Widget Area 1' );
dynamic_sidebar( 'Random Widget Area ' . rand( 1, 5 ) );
dynamic_sidebar( 'Fixed Widget Area 2' );

This example code is very minimal and could be improved in many ways but it works and should serve as a good starting point.

PS: I really like the random widget idea. I will look for a better solution when I have more time. It's a good plugin inspiration :)

share|improve this answer
    
Is it possible to create a new holder widget which will output this line: dynamic_sidebar( 'Random Widget Area ' . rand( 1, 5 ) );and then I could have easy control of in which sidebars to place the randomized area? –  talkol Dec 12 '11 at 8:49
add comment

Though not completely answering your question, you could use the code presented on this page as a starting point. It's just about randomizing the order, but with a few modifications you could make this function do exactly what you need...

share|improve this answer
    
Thanks! I've seen this post, points in the right direction indeed. Hoping there was some off-the-shelf solution, can't imagine I'm the first to want this feature –  talkol Dec 11 '11 at 13:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.