The MU forums have moved to WordPress.org

How do I make a widget default for a theme (12 posts)

  1. dixyantar
    Member
    Posted 13 years ago #

    I want to make certain widgetized divs in my theme contain only specific widget.
    Say, For example, I want sidebar-left in my theme to have only the tagcloud and nothing else. I dont want to manage these widgets from the admin area. Just want to make them default for my theme.
    What code do I use to do this only in my theme and not as a MU plugin as has been shown by some earlier posts?

    I suppose I will have to know internal names of the widgets. But I want specific code so that the categories and archives always show as drop down.
    Is there any way to do this or do I stick to old school and use the MU-plugin.

    Also Is there any way to display widgets contionally , i mean different for the archives page and different for the posts page ?

  2. xenon2050
    Member
    Posted 13 years ago #

    Yes it is possible to do what you ask.
    Put the following code into your theme's sidebar.php file.

    <h3>Tag Cloud</h3>
    <?php wp_tag_cloud('smallest=8&largest=16'); ?>

    Each widget has something similar so just find what you want and put the code in their. Most tell you what the code is and if they don't just find a theme that uses it and then download it, look at their sidebar file and copy the php code.

    As far as the archives page to show something different, you'll need to have something like this:

    <?php if (!is_archives()) : ?>
    <h3>Tag Cloud</h3>
    <?php wp_tag_cloud('smallest=8&largest=16'); ?>
    <?php endif; ?>

    Not sure if that is exactly it, but its the sort of thing you are looking for.

  3. dixyantar
    Member
    Posted 13 years ago #

    That is exactly what I was looking for. Thanks .
    But one more problem, how do I make the category and archives widget always drop down instead of displaying the names.

  4. xenon2050
    Member
    Posted 13 years ago #

    You have to get a plugin that allows for drop down items.

  5. tdjcbe
    Member
    Posted 13 years ago #

    Actually both the archive and category widgets have the dropdown option.

    If you want to set this to always drop down and never allow it not to do something else, I'd just change the code within wp-includes/widget.php. For categories, it starts at line 1092:

    http://trac.mu.wordpress.org/browser/trunk/wp-includes/widgets.php#L1092

    I'd just remove the check and the following 'else' condition.

    Same method would work for the archives as well I would think.

  6. dixyantar
    Member
    Posted 13 years ago #

    Actually that isn't the solution I was looking for. That would require core file editing. But I want my theme to be self sufficient.
    Anyways thanks.
    I think I will make the theme plugin dependent and use some plugin to display the category list and all.

  7. andrea_r
    Moderator
    Posted 13 years ago #

    Use the theme's functions.php file to unregister the default widgets and register your new ones with the drop downs.

  8. xenon2050
    Member
    Posted 13 years ago #

    tbjcbe - Hmm, there is is there? Guess I should look next time; I forget what features they have since I use a plugin for my category and archive.... Now that I think about it I do remember a drop down option... I was thinking of something different.

  9. tdjcbe
    Member
    Posted 13 years ago #

    It used to not be that way. We had plugins replacing those widgets as well until someone pointed it out to me.

  10. xenon2050
    Member
    Posted 13 years ago #

    When I heard drop down I was thinking a dynamic javascript drop down menu... ;)

    Yeah I use a collapsible widget/plugin for myself.

  11. sswells
    Member
    Posted 13 years ago #

    Depending on how complicated you want your solution, there are several plugins for that. The simplest of which would be Display Widgets. If you need more options, there are others: Widget Context and Custom Widgets. I haven't tried the second two, but Display Widgets works in WPMU.

  12. TheMonkeyTail
    Member
    Posted 12 years ago #

    Very nice! I'm was looking for something like this for a long time :D

About this Topic

  • Started 13 years ago by dixyantar
  • Latest reply from TheMonkeyTail