Skip to:
Content
Pages
Categories
Search
Top
Bottom

Modifying the topic tag list

  • How can I modify the tag list (Tags or Your tags) on the topic pages? I’d like to have the tags separated by commas (or whatever) instead of in a list. I’ve tried to edit the template file topic-tags.php, but I can’t figure out how to do it.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Anybody?

    You would have to modify the CSS to list the tags you want. That means playing around with style.css of your template playing with these parts:

    <div id="topic-tags">
    <div id="othertags">
    <ul id="otherstaglist">

    The names will be like #topic-tags, #othertags and something with list item for otherstaglist. I haven’t looked at it, but the list is CSS driven.

    Trent

    Thank you for answering! I’ve been trying to do exactly that, but there are no ids in style.css called #yourtaglist, #otherstaglist etc. Although, I’m not sure I need to edit those ids anyway, since I don’t wanna have the tags in a list.

    For now I have modified the code and edited out the ul and li-tags to make it look like this:

    <?php if ( $user_tags ) : ?>
    <div id="yourtags">
    <?php _e('Your tags:'); ?>
    <?php foreach ( $user_tags as $tag ) : ?>
    <a href="<?php tag_link(); ?>" rel="tag"><?php tag_name(); ?></a> <?php tag_remove_link(); ?>
    <?php endforeach; ?>
    </div>
    <?php endif; ?>

    It works pretty well, but the tags aren’t separated by anything. Is there any way to insert commas between the tags, but not after the last tag?

    That is a great question. Maybe a php expert will give you an idea, but I don’t know that one! I hope someone does! As well, you can probably make that change a plugin as well so that you don’t have to edit the core files! Maybe that same phantom php expert can help us with that as well….

    Trent

    The topic tag list is a list, so marking it up as such is semantically correct, so the best practice way of rendering that list in the way you want is, as Trent suggests, through CSS.

    This article covers inline lists, which is what you’re describing.

    See this for a more terse example.

    Great! Thank you. Yet one problem remains: I can’t find the ids yourtaglist and otherstaglist i the stylesheet. Perhaps I’m supposed to add them myself if I want to change the list appearance?


    chrishajer
    Participant

    @chrishajer

    There are several elements that are not included in the style.css and are thus unstyled. The other one I can think of is /blockquote/ – so, yes, just add these to your theme’s stylesheet if you’d like to modify the presentation of the tag list.

    Alright! I did it. And if anybody wants to know, here’s how:

    This code in the stylesheet

    ul.taglista { list-style: none; margin: 0; padding: 0; }
    ul.taglista li { display: inline; }
    ul.taglista li:after { content: ","; }
    ul.taglista li:last-child:after { content: ""; }

    And this in topic-tags.php

    <?php if ( $user_tags ) : ?>
    <?php _e('Your tags:'); ?>
    <ul class="taglista">
    <?php foreach ( $user_tags as $tag ) : ?>
    <li id="tag-<?php echo $tag->tag_id; ?>_<?php echo $tag->user_id; ?>"><a href="<?php tag_link(); ?>" rel="tag"><?php tag_name(); ?></a> <?php tag_remove_link(); ?></li>
    <?php endforeach; ?>
    </ul>
    <?php endif; ?>

    It won’t work in IE, but that’s fine with me. Thanks for the help!

    “It won’t work in IE, but…”

    IE? Never heard of it.

    Staffan, could you give us a URL to look at?

    Trent

    Sure. Here you go! The forums (as well as the whole site) is still under construction.

    With bbPress v 1 RC – I had the same need and ended up putting this into the topic-tags.php template – and it worked great:

    <div id="topic-tags">
    <?php if ( bb_get_topic_tags() ) : ?>
    <?php foreach ( $tags as $tag ) : ?>
    <?php if ($tag == end($tags)) :?>
    <a href="<?php tag_link(); ?>" rel="tag"><?php tag_name(); ?></a> <?php tag_remove_link(); ?>
    <?php else :?>
    <a href="<?php tag_link(); ?>" rel="tag"><?php tag_name(); ?></a><?php tag_remove_link(); ?>,
    <?php endif;?>
    <?php endforeach; ?>
    <?php else : ?>
    <p><?php printf(__('No <a href="%s">tags</a> yet.'), bb_get_tag_page_link() ); ?></p>
    <?php endif; ?>
    <?php tag_form(); ?>
    </div>

    This added the commas appropriately.

Viewing 12 replies - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.