Viewing 5 replies - 1 through 5 (of 5 total)
  • if you want to do alternating styles like that you have to first work out how you are going to do that in the CSS for the sidebar widgets anyway.

    chances are you’ll use the html for the widget to set a class or something, and you could detect that in the input

    Thread Starter phrz

    (@phrz)

    Hmm, it’s harder than i thought … Do you know of a possible way to add a “before” and “after” widget tag for each widget? Or do you know of a variable that i can set when i register my sidebar?

    register_sidebar(array(
    	'name' => 'blog',
    	'id' => 'blog',
            'before_widget' => '<li id="%1$s" class="widget %2$s">',
            'after_widget' => '</li>',
            'before_title' => '<h2>',
            'after_title' => '</h2>',
        ));
    /* filter widget_content and add ttftitles */
    add_filter('widget_content', 'ttftext_widget_title',2);
    
    function ttftext_widget_title($content='', $widget_id=''){
    	preg_match("/<h2[^>]*>([^<]+)/",$content, $matches);
        $heading=$matches[1];
        $insert_img=the_ttftext( $heading, false );
        $content=preg_replace("/(<h2[^>]*>)[^<]+/","$1$insert_img",$content,1);
        return $content;
    }

    ok, you could do it entirely in the filter by using your own global in the ttftext_widget_title function. flip the global between two values and do some more preg_replacing to insert extra text into the class=”” bit of the LI item to flip between two classes, and to call the_ttftext appropriately.

    something along the lines of (totally untested code off the top of my head)

    global $sidebar_alt;
    $sidebar_alt=($sidebar_alt==”_alt”)?””:”_alt”;
    $insert_img=the_ttftext( $heading, false, “sidebar$sidebar_alt” );

    (and there’s the preg_replace do to put in the class)

    Thread Starter phrz

    (@phrz)

    Thanks, gonna look into that.

    btw. I’ve uploaded my theme to the server and the whole ttfhack stopped working. Could there be some kind of rights issue? The ttftitles still work. The widget text should be replaced (didn’t change the code)

    Any idea?

    did you turn on the filter?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Widget ttftiles advanced text replacing’ is closed to new replies.