can anyone give me a hint how to show the first tag associated with a post only and leave other tags out? I need this for the tab titles of a tabbed content for tags.
Wordpress and Webdesign Forum go41 » WordPress Code Snippets
-
Posted 2 years ago #
-
this code should echo only one (first) tag of a post, you should use it inside the loop or create a loop around this:
<?php $mytags = get_the_tags() ; $count=0; if (!empty($mytags)) {foreach($mytags as $tag) { $count++; if (1 == $count) { echo $tag->name; } } }?>with a short loop around, displaying only one post with offset 8 in a tabbed ui-tab it would look like this:
<?php query_posts('showposts=1&offset=8'); if (have_posts()) { echo '<li><a class="ui-tabs" href="#fragment-1">'; ?> <?php while (have_posts()) { the_post(); ?> <?php $mytags = get_the_tags() ; $count=0; if (!empty($mytags)) {foreach($mytags as $tag) { $count++; if (1 == $count) { echo $tag->name; } } }?> <?php } // end while loop echo "</a></li>\r\n"; } // end if wp_reset_query(); ?>The wp_reset_query(); at the end you need to run more queries with different offset.
With the following code you can echo all tags associated to a post with a space as separator:
<?php $mytags = get_the_tags() ; if (!empty($mytags)) {foreach($mytags as $tag) { echo $tag->name . ' '; }}?>Posted 2 years ago #
Reply
You must log in to post.