Support » Fixing WordPress » Widgetizing a Sidebar

  • I’m relatively new at WordPress, though not with HTML/CSS/PHP.

    I’m creating a site using a recommended template (Cutline 1.4 2-col right) but have fairly seriously edited the site for a custom UI. I have a div I’m treating as a sidebar which now contains an ordered, unbulleted list generated by wp_list_pages, and a button entered into its own nested div. I’m trying to add a simple newsletter signup form (one field, one prompt, one button) below the existing button.

    I found Contact-Form 7 and installed and activated it. It instructs me to copy some code ([contact-form 1 “Contact form 1”]) and to put that code into the page, post or text widget where I want the form to appear.

    But I cannot seem to get a text widget to appear in the sidebar. I figured out I had to call register_sidebar() in the PHP code, and I’ve done that. The function is being called. But no widgets ever appear in the sidebar when I add them via the Dashboard. The Dashboard shows only one sidebar, called Sidebar 1; I don’t know where that name came from because that’s not what I’ve used as an ID for my sidebar code.

    So I think the problem is that I’m not properly widgetizing the sidebar.php file/code. But maybe I’m overlooking something else.

    I’d appreciate help with this. I’ll keep hammering at it in the meantime.

Viewing 5 replies - 1 through 5 (of 5 total)
  • esmi


    Forum Moderator

    You need to place your div-sidebar into a proper sidebar template file (e.g. called sidebar-two.php), widgetize this new sidebar and then call it using <?php get_sidebar('two');?> as required.

    Thanks, esmi. So am I correct in understanding that a file called sidebar.php — which is what I used from the template files — won’t do, that it has to have something more to its name?

    I’m off to see if I can find that answer in the Codex or one of these WP books I have.

    Sigh. I’ve spent three hours today on this problem and even though I consider myself to be reasonably adept at site development and programming, this one eludes me. It appears that sidebar work in WP is either a bit of a kluge or is undergoing continuing shifting. Even the Codex docs say as much.

    I got the sidebar widgetized. The widget I wanted to add showed up fine. Now none of my own added content is appearing at all. Just the widget. I’ve tried converting the whole thing to an unordered list per doc recommendations to no avail. I’m just out of ideas and time. I am beginning to suspect that perhaps I just started out wrong and it’s never been able to get right and may never be able to do so. Unfortunately, I’m missing a deadline mucking with it.

    The learning curve here seems awfully steep to me.

    Well, some progress, sort of accidentally. I found that if rather than encompassing the entire contents of the sidebar.php file in the if statement about the dynamic_sidebar function, I just put everything I want in the sidebar outside of that conditional, both my content and the widget show up. Now I just have to figure out how to get them in the order I want them and I’ll be all set.

    My guess is that my failing here isn’t with WP, it’s with PHP. I should have spent a bit more time analyzing the logic in the sidebar after I added dynamic_sidebar and register_sidebar code.

    Sorry for the noise level here, but maybe some other relative newcomer will read this 10 years from now and see why things don’t work the way they appear to work.



    Forum Moderator

    The widget I wanted to add showed up fine. Now none of my own added content is appearing at all. Just the widget.

    Which you then solved later on, yes? It’s that if statement. If you want the static content to be replaced by the widget, you place all of that content inside the if block. Otherwise, add your static content before or after the if block.

    And posting your solution isn’t noise. It will probably help at least 10 other people with similar problems. 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Widgetizing a Sidebar’ is closed to new replies.