Forums

[resolved] Separate widgets on every category (15 posts)

  1. Leontien
    Member
    Posted 4 months ago #

    I have several categories on my left bar. I need to have different widgets on each category. Once you click on a category, it will only show the widgets that I have placed on that particular category. I have tried several plugins, nothing worked, I have tried to change things in php files, nothing worked, please help.

    My site is http://moneyinpoliticsohio.org/
    You will now see that all the widgets are the same on the home page and on each category.

  2. tribalNerd
    Member
    Posted 4 months ago #

    Hello Leontien... Just to let you know, your website returned a Malware Detected warning.

    Without looking at the site, typically these settings are in the sidebar.php and functions.php file. The sidebar calls the widgets and should be the file that tells the widgets to turn on/off for pages, posts, categories, etc... The functions file defines the sidebars, which displays them in the admin.

    Some pages that may help:
    http://codex.wordpress.org/Customizing_Your_Sidebar#New_way_of_adding_sidebars
    http://codex.wordpress.org/Function_Reference/register_sidebars

  3. Leontien
    Member
    Posted 4 months ago #

    Thanks! The problem is that I can't find the functions or sidebar php in my FTP. Can you help me find it?

  4. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

    That site is coming up with a clean scan.

    I can't find the functions or sidebar php in my FTP

    Try looking in your current theme's folder in wp-content/themes.

  5. Leontien
    Member
    Posted 4 months ago #

    Great, I found it, when I add

    <?php if ( function_exists ('register_sidebar')) {
        register_sidebar ('custom');
    } ?>

    [Please post code or markup snippets between backticks or use the code button.]

    to my functions.php (at the bottom), I can't even get to my widgets anymore, there is an error message. It would be great if someone could help me put a certain code somewhere. i really appreciate the help.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

    Try:

    if ( function_exists ('register_sidebar')) {
        register_sidebar ('custom');
    }
  7. Leontien
    Member
    Posted 4 months ago #

    I put in;

    if ( function_exists ('register_sidebar')) {
        register_sidebar ('custom');
    }

    [Please post code or markup snippets between backticks or use the code button.]

    in the functions.php (or should I have put it in the widgets.php?) and again error message. Can I just put it on the bottom?

  8. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

    Just make sure it goes before any ending ?> tag in functions.php.

  9. Leontien
    Member
    Posted 4 months ago #

    Yes, I added that ?> after it. Okay, it worked, I can see my widget page (the back end)... But I still don't see how I can use it, I mean, I was hoping that in the widget (for example a text widget) I would be able to scroll down and it would tell me where I want this specific text to go, under which category.

  10. Leontien
    Member
    Posted 4 months ago #

    My next step would possibly be:

    'custom' would mean you have to create a custom sidebar-file under the name sidebar-custom.php. Sidebars get indexed. Your default sidebar (sidebar.php) gets indexed as 1. Every succeeding one will have an index higher than 1. You will see your sidebars now listed in 'Appearance' -> 'Widgets'.

    I don't understand this, could anyone explain in layman terms? THANKS!

  11. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

    No - that won't work with out quite a lot of theme editing/customisation. Have a look at http://wordpress.org/extend/plugins/widget-logic/ instead.

  12. Leontien
    Member
    Posted 4 months ago #

    I have looked at this plugin before. When I activate it though, my site goes into error. This is what is says:

    Parse error: syntax error, unexpected ':' in /var/www/vhtdocs/userweb51311/html/wp-content/plugins/widget-logic/widget_logic.php(169) : eval()'d code on line 1 Parse error: syntax error, unexpected ':' in /var/www/vhtdocs/userweb51311/html/wp-content/plugins/widget-logic/widget_logic.php(169) : eval()'d code on line 1

  13. Leontien
    Member
    Posted 4 months ago #

    Will this help:

    if(function_exists('register_sidebar')) {
    foreach((array)(get_categories()) as $category) {
    register_sidebar(array(
    'name' => 'Categorie : ' .$category->cat_name,
    'before_widget' => '<div id="%1$s" class="%2$s widget">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>', ));
    }

    foreach((array)(get_pages()) as $page) {
    register_sidebar(array(
    'name' => 'Page : ' .$page->post_name,
    'before_widget' => '<div id="%1$s" class="%2$s widget">',
    'after_widget' => '</div>',
    'before_title' => '<h3 class="widget-title">',
    'after_title' => '</h3>', ));
    }
    }

    I added this to functions.php but I can't seem to find it back on the back end anywhere?

  14. esmi
    Theme Diva & Forum Moderator
    Posted 4 months ago #

    What version of WordPress are you using?

  15. Leontien
    Member
    Posted 4 months ago #

    I just found the answer to my question. It's a plugin called "Conditional Widgets".
    Thanks!

Reply

You must log in to post.

About this Topic