• Is there a way to add the category of each post into the widget code in functions.php so that they can be targeted by category in the CSS? I found directions to do this in the Loop: e.g. <div id="post" <?php post_class(); ?> > Here is one of my added sidebars in functions.php:

    register_sidebar(array(
            'id' => 'basic',
            'name' => __('Basic Sidebar'),
            'description' => __('Sidebar used on most pages'),
    		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
    		'after_widget' => "</aside>",
    		'before_title' => '<h3 class="widget-title">',
    		'after_title' => '</h3>',
        ));

    This assigns two classes to each widget: “widget” and the name of the widget or the plugin that generated the widget, but if I use the same plugin to add more than one widget there’s no consistent way to target them individually.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Try using the id that is being assigned to each widget.

    Thread Starter petroglyphic

    (@petroglyphic)

    The number which makes each id unique is a result of what order the widget was added to the sidebar, so it’s not consistent. The “Contact” post could be “advanced-recent-posts-2” on one sidebar and “advanced-recent-posts-1” on another, and if the user adds widgets in the admin the numbers will be different again.

    I’m trying to give the user control over the content without giving them control over the styling!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘register sidebar, before_widget: get post category’ is closed to new replies.