asquare
Member
Posted 3 years ago #
hi
I'm using a custom select to retrieve my posts for my posts page instead of the loop. I need to get each posts tags as I display the post.
get_the_tags($post->ID);
this (above) seems to work and then I have to construct my string from the arrays, making sure I add links and commas between tags etc.
is there an easier way to do this?
a+
gar
Dunkkan
Member
Posted 3 years ago #
Hi asquare, did you get a solution to this ? I'm involved in the same issue.
<?php the_tags('<span class="taglist"><strong>Tags:</strong></span> ', ', ', ''); ?>
Dunkkan
Member
Posted 3 years ago #
Hi whooami, I tried this inside a custom query with get_posts, but it didn't work.
Here's what I found to solve it. If someone knows a better way, please share it !
<?php
$posts = get_posts('category=4&numberposts=1');
foreach($posts as $post):
setup_postdata($post);
?>
<?php the_title(); ?>
<?php the_content(); ?>
<!-- HERE IT COMES THE TRICKY PART -->
<?php $posttags = get_the_tags($post->ID);
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
?>
<?php endforeach; ?>