WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] help with the_tags display

[Resolved] help with the_tags display

  • I have the_tags in a post template, in a narrow column. The only way I could get the tag to display below the intro text “Most recent trip” was like this..

    <?php the_tags('Most recent trip:&nbsp; &nbsp; &nbsp &nbsp;&nbsp;&nbsp;&nbsp;'); ?>

    ..as the line spaces force the output out and below the intro, because of the narrow column. Awkward I know. A better solution is surely welcome, but it works.

    But my real issue is that I cannot figure out how to get the_tag to display with an h tag, or em tag, or any tag. I’ve read the_tags codex but it doesn’t appear to address what I’m trying to do. Only seems to deal with before, seperater, and after. I don’t know that I want to change global css for tags, .. just want h4 in this instance, any advice?

    thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Moderator Jan Dembowski

    @jdembowski

    Volunteer Mod. & Brute Squad

    Give this a look:

    http://wordpress.org/support/topic/the_tags-and-add_filter?replies=4#post-732457

    If I understand it correctly, you want to be able to add something like a <em> tag to er, the post tags.

    Modifying the code from that link, I can wrap the tag links with '<em>[' ... ']</ em>' like so:

    add_filter( 'term_links-post_tag' , 'mh_add_em' );
    
    function mh_add_em( $c ){
            foreach( (array) $c as $k => $v ){
                    $a[] = '<em>[' . $v . ']</em>';
            }
            return $a;
    }

    That’s just an example but I think you get the idea. Add that to your functions.php file.

    whoa, never thought it would require a new function.. Thanks a bunch, I’ll give it a go. I’ll have a look at the link and see if I can understand what you did.

    Hi,

    I’m sure you’ve tried something like:

    <?php the_tags('<h4>The Tags Heading</h4><ul><li>','</li><li>','</li></ul>'); ?>

    which works for me to put an h4 at the head and put the tags in a ul.

    /peter

    Thanks Peter, but that gets the tag heading as h4, I’m trying to get the_tag itself as h4.

    "Tag Heading"
    (followed by)
    <h4>Tag 1</h4>
    <h4>Tag 2</h4>
    <h4>Tag 3</h4>
    ect..

    I haven’t tried the function Jan posted yet.

    Based on what you did I tried it this way:

    <?php the_tags('Most Recent Trip:<h4><ul><li>','</li><li>','</li></ul></h4>'); ?>

    it does what I want!

    Thanks so much!

    Also, I did try the function, it put an odd slanted bracket on either side of the_tag, but no em.

    Moderator Jan Dembowski

    @jdembowski

    Volunteer Mod. & Brute Squad

    Also, I did try the function, it put an odd slanted bracket on either side of the_tag, but no em.

    Well, yes, that’s what it’s supposed to do, the em caused it to be slanted… 🙂

    It was just an example. You could have replaced ”[‘ … ‘]” with ‘<h4>…</h4>’ meaning you could wrap the tags in anything you’d like.

    Although pkwooster’s solution is simpler and does work for you so you’re good to go. 😉

    Thanks again jan, that’s how I learn this stuff.

    So you say this

    $a[] = '<em>[' . $v . ']</em>';

    becomes

    $a[] = '<h4>[' . $v . ']</h4>';

    I’ll try it. Also wondered what may be invoved getting it for one instance in one template.
    The other solution does appear to work but the font size doesn’t change as much as it should, it’s odd. It gets thicker but not really much bigger, not like my other h4 tags. It may be some predsfined class in this author-box column I’m trying to work in. But I’ll try your solution again see if Iget the same. If so I have another issue to pursue.

    Moderator Jan Dembowski

    @jdembowski

    Volunteer Mod. & Brute Squad

    $a[] = ‘<h4>[‘ . $v . ‘]</h4>’;

    Yes, but I used the [ .. ] for illustrative purposes. If you only want the <h4> ... </h4> then it’s just

    $a[] = '<h4>' . $v . '</h4>';

    And that function will wrap the WordPress tags in <h4>.

    Thank you, now I get it.

    I was really suprized when

    <h4><?php the_tags();?></h4>

    had no effect. But I’ve only applied markup to post output, never tags or even category links.

    So I assume there’s no way to get a single instance of this, or at least not an easy way? I’m a bit concerned about doing this for all instances of the_tag, in case I want to use them in the standard way for other things on the site.
    All I want to do is anything that will make individual instances of the tags diifferent from the regular p class a links on the page, so they’ll stand out. They actually act as the primary navigation for my site.

    Moderator Jan Dembowski

    @jdembowski

    Volunteer Mod. & Brute Squad

    So I assume there’s no way to get a single instance of this, or at least not an easy way?

    But there is and it doesn’t take a lot of effort. That filter is always used within a loop, so you can add almost any conditional for when it’s applied.

    For example, if you wanted it to be used for posts, but not pages or the home page, you can modify it like so

    if ( is_single() ) {
       add_filter( 'term_links-post_tag' , 'mh_add_em' );
    }

    And that will get applied only when it’s via a single post page.

    Here’s a list of Conditional Tags to look and play with 😉

    http://codex.wordpress.org/Conditional_Tags

    okay, it’s coming together. I’ve used conditionals but never for a “filter’ unless the filter wss arguments in a query. So this “add_filter” is a new toy for me now. Just what I needed. (haha)

    I actually have to recreate my entire page before I can try it, I’m trying to customize a rather complex page template, braking all over the place.

    Thanks!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Resolved] help with the_tags display’ is closed to new replies.