views:

439

answers:

1

Hi Guys,

I am using this code to get the tags in my wordpress posts for a theme

`<?php
$posttags = get_the_tags();
if ($posttags) {
  foreach ($posttags as $tag) {
     $tagnames[count($tagnames)] = $tag->name;
  }
  $comma_separated_tagnames = implode(", ", $tagnames);
  print_r($comma_separated_tagnames);
}
?>`

The PROBLEM is that it is returning tags for "all posts" not just individual posts, and I think the problem is that if a post DOESNT have tags - it just inserts tags anyway.

Can anyone help modify this so:

  1. It return tags only for a post - not all tags
  2. If there are no tags for a post, dont return anything

? Really appreciate any help

P.S - Can check out here for the wordpress docs

A: 

Try using:

<?php the_tags(); ?>

Inside the 'Loop'.

Function Reference

Paul Sheldrake