SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot hephaistion's Avatar
    Join Date
    Oct 2006
    Location
    Polis Chrysochous, Cyprus
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wordpress - getting tags outside loop on single page

    Situation: On my single post pages I have a column between the post and sidebar. In this column i have some tools for email, print this, share. Below this I want to have an "Other stuff in..." followed by a list of tags for that post.

    Current Solution:

    PHP Code:
    <div id="tagged">
                <h3>Other stuff on...</h3>
                <?php
       
    global $post;
       foreach(
    get_the_tags($post->ID) as $tag) {
          echo 
    '<a href="http://www.blog/tag/' $tag->name '/" rel="tag">' $tag->name '</a> &middot; ';
       }
    ?>
            </div>
    Problem: The php only gives me the name of the tag without a link so I have to very inelegantly turn it into one. Thankfully wp is case-insensitive so single word tags work fine. I could even work out the php to replace spaces with hyphens for multiword tags and remove the final dot. But the whole thing seems a bit unnecessarily Heath Robinson.

    What I would like is to use tag_link in the url and name in anchor. I'll work out final dot myself.

    It's a niggle and I cld get round it but I'd rather it was 'clean.'

    Thanks, as always, for any help you can offer.

    M.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should be able to do this after The Loop in your single.php to use the_tags. $post is still in scope so you can use the_post() to put yourself back in The Loop as far as the template functions are concerned.

    PHP Code:
    <?php        
    the_post
    ();
    the_tags();
    ?>
    Worked on my theme at least.

  3. #3
    SitePoint Zealot hephaistion's Avatar
    Join Date
    Oct 2006
    Location
    Polis Chrysochous, Cyprus
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dan, you always come through! Thanks very much. Every problem I had sorted.
    M


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •