• Resolved miroslav

    (@miroslav)


    Widgets are so easy to use! Drag and drop…

    But, is there a way to associate different widgets with different template files?

    For example, I want my sidebar to be different for home, different for archive, different for pages, and different for single posts.

    I can do this easily for non-widgetized themes by modifying the template files. But, what about those themes that use widgets? Any way to do this?

    Thanks! ??
    Miroslav

Viewing 15 replies - 1 through 15 (of 15 total)
  • Thread Starter miroslav

    (@miroslav)

    Anyone?

    conditionally include the widget code in your theme’s sidebar? We have all those conditional tags for is_home, etc.

    Or did I miss the point?

    Thread Starter miroslav

    (@miroslav)

    conditionally include the widget code in your theme’s sidebar?

    Wouldn’t that turn on/off all the installed widgets at once? If so, that’s not what I need.

    Say, I have 5 widgets installed. Here’s what I want:

    home – widgets: 1, 2, and 3
    single – widgets: 4 and 5
    page – widgets: 1, 3, and 5
    etc.

    Thread Starter miroslav

    (@miroslav)

    Anyone?

    bumping a thread after an hour won’t do you any good.

    Thread Starter miroslav

    (@miroslav)

    It was 1 day, not 1 hour, miklb…

    For example, I want my sidebar to be different for home, different for archive, different for pages, and different for single posts.

    I can do this easily for non-widgetized themes by modifying the template files. But, what about those themes that use widgets? Any way to do this?

    You can do this with widgets as easily as hard-coding in your template files. I’m running widgets to seven(7) different sidebars.

    ie:
    articles (global article categories)
    articles sub (global article single)
    books (main cat)
    books sub (main sub cat)
    books sub sub (main sub-sub cat)
    books sub sub 2 (single for sub & sub-sub)
    search

    Books is a legitimate e-commerce bookstore. I presently use ten (10) text boxes (and a host of other widgets) to display different information in different sections of my site on different sidebar templates.

    To call the individual widgets text boxes per specific sidebar template but NOT for other sections in my site, I use:

    HTML/PHP
    <?php if ( function_exists('dynamic_sidebar') && dynamic_sidebar('articles-sidebar') ) : else : ?>

    where the ‘articles-sidebar’ I simply change to reflect the template I want the widge to appear in.

    In functions.php I coded this:

    {
    register_sidebar(array(
    ‘before_widget’ => ‘<div id="%1$s" class="widget %2$s">‘,
    ‘after_widget’ => ‘</div>‘,
    ‘before_title’ => ‘<p class="subheading">‘,
    ‘after_title’ => ‘</p>‘,
    ‘name’=>’articles-sidebar’,
    ));

    where ‘name’ articles-sidebar I ADDED a new entry directly underneath that said ‘name=’articles-sub-sidebar (complete code, of course) and so forth for each template I want the widgets to appear on.

    Does that help?

    Unless someone else has a cleaner way of doing things ??

    Thread Starter miroslav

    (@miroslav)

    Super info KatGirl, thanks! ??

    But, wouldn’t hard-coding the widgets into your template files do away with the key widgets’ functionality, namely the ability to just drag and drop widgets to your sidebar from your Presentation > Sidebar Widgets menu?

    But, wouldn’t hard-coding the widgets into your template files do away with the key widgets’ functionality, namely the ability to just drag and drop widgets to your sidebar from your Presentation > Sidebar Widgets menu?

    Ok. I think you’ve confused yourself.

    When you install the plugin Sidebar Widgets, you upload to wp-content/plugins/ section and activate inside your Admin/Plugins.

    You also have to upload the functions.php file into your current theme folder as well.

    wp-content/themes/your current theme

    Your version of hard-coding and mine are vastly different. I’m only adding the <dynamic php code> to my sidebar templates to call the plugin into play. Nothing else. Much like any other plugin.

    But, before I can call the plugin into play inside my template file, I have to tell the plugin which template I want it to display the widgets on.

    To do this I have to open functions.php and add multiple instances of template names code, as I suggest above, then save, then re-upload and the additional sidebars will appear in Manage>>Sidebar Widgets section.

    From there you can drop and drag whatever you like into the individual sidebars.

    Have I confused you yet?

    Thread Starter miroslav

    (@miroslav)

    I had to read your 2 posts very carefully several times before I got your point (my knowledge of PHP is very limited). Quite an elegant solution, although I hope that in the future the widgets plugin will allow users to select which widgets will show up on which template via an easy-to-use admin menu.

    I agree. But my answer probably sounded long-winded, because most people aren’t using so many sidebars.

    In normal instances, it would be a matter of just inserting the php code into one or two templates and bob’s your uncle.

    In all seriousness, however, the process is dead esay and very minimal in time. If you want I can email you my functions.php to show you what I did.

    Thread Starter miroslav

    (@miroslav)

    If you want I can email you my functions.php to show you what I did.

    That would be fantastic! Thanks! ??

    Please email to:
    wordpress A. T. mikino D. O. T. com

    maybe I’m a bit late ??
    can I have it in my mail too? nonletter -a-t gmailcom

    All you need to do is call a different sidebar file from the different pages you mentioned.

    index calls sidebar.php
    singel calss sing-sidebar.php
    etc…

    Then have copied instaces of the widgets ready to drag them into the dynamic sidebars that correspond to te called sidebar file …

    -FOP-

    This thread is marked [resolved] but I don’t think it is. I recently posted asking this exact same thing but it did not resolve the issue for me. I have been trying your solution FOP, and it’s not working.

    Using the above example:
    index calls sidebar.php
    single calls sing-sidebar.php

    But it seems that only sidebar.php is showing up in the “Widgets:Sidebar Arrangement” editor-pane. And if I use register_sidebars(2); instead of register_sidebar(); then a second sidebar shows up in the editor-pane, but it does not correspond to sing-sidebar.php.

    Of course this behavior makes sense because how would WP know to find sing-sidebar.php? But it does not resolve the issue: how would I make WP recognize it?

    Thanks!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Excluding widgets from certain template files’ is closed to new replies.