WordPress.org

Forums

[resolved] How to get post tag? (6 posts)

  1. Luigino
    Member
    Posted 5 years ago #

    Hello everyone...

    I have some posts which I assigned a tag to each of them to recognize when I do in a template:

    loop...
    echo '<div class="blahblah"><a href="'; echo get_page_link(xxx); echo '&focus='; echo the_tags(); echo '" alt="'; echo the_title();....
    end loop...

    using the_tags() I thought it would return the tag I assigned to that post but I get something like "Tags: blah blah...."
    How I can get the single tag I assigned to the post??...

    Thanks in advance to all!!
    Luigi

  2. MichaelH
    Member
    Posted 5 years ago #

    You don't need to use echo with Template Tag, the_tags().

    If you want to return the post tags to a variable you can do this:

    $tags = wp_get_post_tags($post->ID);
  3. Luigino
    Member
    Posted 5 years ago #

    but with $tags I get an Array...since each post has only one tag just to identify that post, how I can get the tag from $tags's array?.. with $tags[0] it doesn't return the tag....

  4. MichaelH
    Member
    Posted 5 years ago #

    <?php
    $tags = wp_get_post_tags($post->ID);
      if ($tags) {
        foreach($tags as $tag) {
            echo '<p>' . $title . '<a href="' . get_term_link( $tag, 'post_tag' ) . '" title="' . sprintf( __( "View all posts in %s" ), $tag->name ) . '" ' . '>' . $tag->name.'</a> has ' . $tag->count . ' post(s). </p> ';
        }
      }
    ?>
  5. Luigino
    Member
    Posted 5 years ago #

    Ah there we go! Thanks a lot MichaelH....
    Last question...outside the index.php, in this case in a theme for a plugin, where I adopt the query_posts(...), I get this error:

    Use of undefined constant date - assumed 'date' in /home/binago/public_html/wp-
    content/plugins/mailpress/mp-includes/class/MP_Mail.class.php(247) : eval()'d code at line 17

    so I supposed it's due for this:

    $today = getdate();
    $args=array(
    'category__not_in'=>array(24,44,127),
    'caller_get_posts'=>1,
    'year'=>$today["year"],
    'monthnum'=>$today["mon"],
    'day'=>$today["mday"]-1,
    'orderby'=>date,
    'order'=>DESC
    );
    query_posts($args);

    precisely in the 'orderby'=>date maybe outside the usual loop posts doesn't work...what do you think? is there maybe an alternative for this 'orderby'=>date?...

    Thanks
    Luigi

  6. MichaelH
    Member
    Posted 5 years ago #

    Luigino - please start another topic with that question.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.