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.

I'm searching for a solution where the user can define some sidebar widgets for himself (only text and images). The user should have the possibility to choose a different sidebar for a different page.

WidgetLogic and so on only allow the configuration on which page a sidebar widget should be shown (also a standard user has in this case no rights and I'd have to change that). There are other solutions which are more comfortable but the user would still have to know HTML to define the sidebar.

Do you know any practicable solution?

share|improve this question

2 Answers 2

There's a brute force method you can use.

When you register your sidebar, you give it an ID and a name, then you use that ID and name on the sidebar template to display it.

What if you appended the ID of the page to that identifier? So instead of 'mainsidebar' you had 'mainsidebar'.$post->ID?

Step 1: In functions.php do a WP_Query loop to grab all the pages. Instead of displaying the posts however, register a sidebar, and append the posts ID to the identifier. Append its title to the pretty name so your not looking at numbers in the admin panel Step 2: In your page template modify your sidebar call to include the post ID on the end like you did earlier.

Advantages:

  • Every page has a sidebar unique to it
  • Total control over what goes where
  • Simple quick and easy implementation

Disadvantages:

  • Doesn't scale. 100 pages means 100 sidebars, you'll have to be a bit more selective, perhaps a post meta toggle that you can filter on in the WP_Query registration loop
  • Shared content becomes tedious to re-enter for every page. This can be avoided by having another sidebar that they all share that isn't per page.
share|improve this answer

I used MoreFields and MoreTypes for this type of task. Works wonderfull (except the User has to put in some IDs).

MoreFields: User put in some ID on each page
MoreTypes: Sidebar List with alls Sidebars

<div id="custom-sidebar">
    <?php
        $fields = get_post_custom(get_the_ID());
        /*
        echo '<pre>';
        print_r($fields);
        echo '</pre>';
        */
        if(!empty($fields['sidebar'][0])){
            global $wp_query;
            $wp_query = new WP_Query();

            $queryString['post_type'] = "sidebar";
            $queryString['p'] = $fields['sidebar'][0];

            $wp_query->query($queryString);

            if($wp_query->have_posts()){
                while ($wp_query->have_posts()) : $wp_query->the_post();
                    the_content('',TRUE);
                endwhile;
            }
        }
    ?>
</div><!-- #custom-sidebar -->
share|improve this answer

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.