• Resolved jzk

    (@jzk)


    Hello,

    In order to display the categories and child categories of each post, I am using this script (find there: http://wordpress.org/support/topic/390397?replies=9 ) :

    <?php
    $args=array('orderby' => 'none');
    $terms = wp_get_post_terms( $post->ID , 'category', $args);
    foreach($terms as $term) {
      echo '<a href="' . esc_attr(get_term_link($term, 'category')) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> ';
    }
    ?>

    I want to add properly a separator, any ideas ?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • If you used something like:

    echo '<a class="mycatlist" href="' . esc_attr(get_term_link($term, 'category')) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> ';

    you could then add a border-separator using CSS:

    .mycatlist {border-bottom:1px solid #999;}

    Thread Starter jzk

    (@jzk)

    Thanks for this answer.

    It could be a way but ideally I would like to separate the category like this :
    cat-name_1 + cat-name_2 + cat-name3

    Do you literally want to add a “+” sign between each link? Or have I misunderstood?

    Thread Starter jzk

    (@jzk)

    Yes I want literally add a “+” or “//” between each link.
    There is a way adding like that :
    echo '<a href="' . esc_attr(get_term_link($term, 'category')) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> + ';

    But after the result is :
    cat-name_1 + cat-name_2 + cat-name3 +

    Try:

    <?php
    $args=array('orderby' => 'none');
    $terms = wp_get_post_terms( $post->ID , 'category', $args);
    $t = count($terms);
    $c = 0;
    foreach($terms as $term) {
      $c++;
      echo '<a href="' . esc_attr(get_term_link($term, 'category')) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a> ';
      if($c < $t ) echo ' + ';
    }
    ?>
    Thread Starter jzk

    (@jzk)

    Great it works ! Really thanks a lot ! 😉

    Cool! Glad to have helped.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Adding separator with wp-get-post-terms’ is closed to new replies.