ThemeShaper Forums » Thematic

changing thematic_before_widget() in child theme

(3 posts)
  • Started 9 years ago by cee
  • Latest reply from circlecube
  • This topic is not resolved
  1. cee
    Member

    I'd like to change the following code:

    // CSS markup before the widget
    function thematic_before_widget() {
            $content = '<li id="%1$s" class="widgetcontainer %2$s">';
            return apply_filters('thematic_before_widget', $content);
    }

    which is located in /thematic/library/extensions/widgets.php

    i have a child theme, so i don't want to actually touch that file. how can i change the default before (and after) widget html output without editing the parent thematic theme?

    Posted 9 years ago #
  2. @cee - from what I understand you would write a filter for thematic_before_widget.

    add_filter('thematic_before_widget', 'thematic_before_widget_filter');
    function thematic_before_widget_filter($content) {
    	//edit the content
    	return $content;
    }

    I'm also interested in updating the thematic_before_widget content. I want to add a counter to the class of my widgets so that I can style each one according to it's position in the widget area. I understand that I would create a filter, but am not sure how to increment a count inside a filter like this, can I make a global variable? I guess it would count all the widgets on the whole site then?

    Posted 9 years ago #
  3. well, I've played with it a bit and was able to get some progress

    $widget_count = 0;
    add_filter('thematic_before_widget', 'thematic_before_widget_filter');
    function thematic_before_widget_filter($content) {
    	//	$content = '<li id="%1$s" class="widgetcontainer %2$s">';
    	//edit the content
    	global $widget_count;
    	$content = substr($content, 0, -2) . ' widget_count_' . $widget_count++ . '">';
    	return $content;
    }

    The problem here is it gives widgets the same counter class in each widget area. So all the widgets in the primary area get the same widget_count_0 and secondary widget_count_1. Any obvious way anyone sees to make it increment per widget rather than per widget area?

    Also, I only want to apply this to a single widget area, I guess I'd just wrap the contents of the filter with an if statement but how do I access the widget area? I see in widget-extensions.php that the thematic_before_widget_area function has if statements to check which aside it's working with, but not sure how to access that $hook var from my function. Thanks for any pointing in the right direction.

    Posted 9 years ago #

RSS feed for this topic

Reply

You must log in to post.