0

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?

2 Answers 2

0

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.
0

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 -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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