ThemeShaper Forums » Thematic

[closed]

Separators for categories-widget (php solution needed! css not working)

(4 posts)
  • Started 3 years ago by mo
  • Latest reply from helgatheviking
  • This topic is not resolved
  1. Hi Forum!

    I wanted to show my cats and tags als block-text in the (header)sidebar of my new website. I used widgets to configure that menu. But when you show a list as block-text you need separators to make the visitor able to differentiate between the tags or cats to choose…

    Well – after some research I found out, that there already are some lines of code, that wordpress is using to define how the tags widget is working and looking. (see code below)
    So I added it to my functions.php and altered it a bit.
    This works fine now… every tag is separated by a "|" from the next tag.

    For the categories-widget I wasn't able to find out how this works in php or if there already is some code I could use to build in a separator. So I thought about it a while and then used some CSS(3?) code which worked (In opposition to the tags-widget the categories-widget is using "li" classes to define every item),…
    BUT! it only works fine in Firefox not in Safari…
    I'd appreciate if anyone knows a php solution for my problem, because Safari ignores the "li:last-of-type:after" and shows a "|" after the last cat which doesn't really look fine…

    Well, Here we go for the code,
    PHP for the tags-widget-separators:

    // configure Tag-Cloud
    function my_tag_cloud($defaults) {
    $args = array(
    'smallest' => 7, 'largest' => 7, 'unit' => 'pt', 'number' => 25,
    'format' => 'flat', 'separator' => " | ", 'orderby' => 'name', 'order' => 'ASC',
    'exclude' => '', 'include' => '', 'link' => 'view', 'taxonomy' => 'post_tag', 'echo' => true
    );
    $args = wp_parse_args( $args, $defaults );
    $tags = get_terms( $args['taxonomy'], array_merge( $args, array( 'orderby' => 'count', 'order' => 'DESC' ) ) ); // Always query top tags
    
    if ( empty( $tags ) )
    return;
    
    foreach ( $tags as $key => $tag ) {
    if ( 'edit' == $args['link'] )
    $link = get_edit_tag_link( $tag->term_id, $args['taxonomy'] );
    else
    $link = get_term_link( intval($tag->term_id), $args['taxonomy'] );
    if ( is_wp_error( $link ) )
    return false;
    
    $tags[ $key ]->link = $link;
    $tags[ $key ]->id = $tag->term_id;
    }
    
    $return = wp_generate_tag_cloud( $tags, $args ); // Here's where those top tags get sorted according to $args
    
    $return = apply_filters( 'my_tag_cloud', $return, $args );
    
    if ( 'array' == $args['format'] || empty($args['echo']) )
    return $return;
    
    echo $return;
    }

    CSS(3?) for the cats-widget-separator:
    the "li:last-of-type:after" gets ignored by Safari,…

    .widget_categories li{
    display: inline;
    font-style: normal;
    font-weight:normal;
    font-size:10px;
    line-height:15px;
    text-transform:none;
    }
    
    .widget_categories li:after{
    content: " | ";
    }
    
    .widget_categories li:last-of-type:after{
    content: none;
    }

    Thank you in advance!

    Posted 3 years ago #
  2. No Idea anyone?
    I just kept searching but cannot find the PHP-code that adresses the wp-categories-widget…
    Sorry for pushing my thread - I'm in need for a solution!

    Posted 3 years ago #
  3. what a pity,… just a tip in the right direction would help,
    please!

    Posted 3 years ago #
  4. after digging around in the wordpress files, the default categories widget is generated by

    class WP_Widget_Categories extends WP_Widget

    in the default-widgets.php file in wp-includes

    however, arent the categories generated in a ul list. can't you use the list-style css attribute and apply a bullet? you could also apply a border? or a background image? why isnt a CSS solution satisfactory?

    Posted 3 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.