0

I have a widget which displays the latest projects as thumbnails on my website. When I mouse over a thumbnail the project title appears; this is the code for title:

<h2><?php echo get_the_title(); ?></h2>

So, I'm thinking to display also the tags from that specific project, to be something like beautiful, nature, landscape

Is this possible, or could you give me some suggestions on how to achieve this ? Thanks!

2

By what code you've posted, it seems like you've got a secondary loop set up (using a WP_Query object). So to display the current' posts tags you can use:

  • the_tags - to print a list of the post's tags
  • wp_tag_cloud - to print a tag cloud.
  • get_the_tags - to return an array of tag objects, which you can then use to display the tags however you'd like.
1

Tags can be shown outside the Post loop using the global functions.

Step 1 : Get a PHP Code Widget (this solved many problems)

Step 2 : Place the Code <?php the_tags(); ?> in widget and Save.

Check Tags Documentation to tweak display order.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.