WordPress.org

Ready to get started?Download WordPress

Forums

How to show tags IN a post? (10 posts)

  1. tjalling474
    Member
    Posted 3 years ago #

    I am building a reviews site which means that the layout of most of the posts is the same. The posts starts with some information, like this:

    Year: 2009
    Director: ...
    Genres:
    Summary: blablabla

    I want the tags to show up after genres and not at the end of the post.
    Does someone have the same problem and has somebody found a solution?

  2. xdesi
    Member
    Posted 3 years ago #

    You want the post tags to show after the word Genres?

    Then you need to edit the template file responsible for where this information is outputted (probably single.php) and use the_tags() to display the tags where you want them.

  3. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    shortcode ?

    function tags_in_post($atts) {    // [tags] outputs post's tags in a span
    global $post;
    $tags = '<span class="post-tags">';
    ob_start();
    the_tags( '<span class="post-tags"><strong>Tags:</strong> ', ', ', '</span>' );
    $tags = ob_get_flush();
    return $tags;
    }
    add_shortcode ('tags', 'tags_in_post');

    http://codex.wordpress.org/Shortcode_API

  4. Gerald
    Member
    Posted 3 years ago #

    yes.. I was thinking of shorcode as well.. was writing it when alchymyth posted...

    You can either use @alchymyth's code,

    Or mine:

    function dtags_func($atts) {
        extract(shortcode_atts(array(
    		'before' => '',
    		'separator' => ', ',
            'after' => '',
    	), $atts));
    
    	the_tags($before,$separator,$after);
    }
    add_shortcode('dtags', 'dtags_func');

    Or download the following plugin, upload and activate it.
    http://fusedthought-labs.googlecode.com/files/display-tag-shortcode.zip

    Usage:
    [dtags]

    or

    [dtags before=' ' separator=', ' after=' ']

    Cheers

  5. tjalling474
    Member
    Posted 3 years ago #

    Thanks a lot :D
    That will do the trick. But in which file should I put:

    function tags_in_post($atts) {    // [tags] outputs post's tags in a span
    global $post;
    $tags = '<span class="post-tags">';
    ob_start();
    the_tags( '<span class="post-tags"><strong>Tags:</strong> ', ', ', '</span>' );
    $tags = ob_get_flush();
    return $tags;
    }
    add_shortcode ('tags', 'tags_in_post');

    or

    function dtags_func($atts) {
        extract(shortcode_atts(array(
    		'before' => '',
    		'separator' => ', ',
            'after' => '',
    	), $atts));
    
    	the_tags($before,$separator,$after);
    }
    add_shortcode('dtags', 'dtags_func');

    In single.php?

  6. Gerald
    Member
    Posted 3 years ago #

    @tjalling474

    The codes should be put into your theme's function.php

  7. tjalling474
    Member
    Posted 3 years ago #

    Thanks a lot. It works perfect now! =D

  8. tjalling474
    Member
    Posted 3 years ago #

    I used the first shortcode that you gave me:

    function tags_in_post($atts) {    // [tags] outputs post's tags in a span
    global $post;
    $tags = '<span class="post-tags">';
    ob_start();
    the_tags( '<span class="post-tags"><strong>Tags:</strong> ', ', ', '</span>' );
    $tags = ob_get_flush();
    return $tags;
    }
    add_shortcode ('tags', 'tags_in_post');

    and I deleted the Tags: in this partthe_tags( '<span class="post-tags"><strong>Tags:</strong> ', ', ',
    otherwise you get Genres: Tags: ....

    There is only a problem now. The tags do not only show after Genres: but also at the beginning of my post like this:

    Test
    (EDIT POST)
    POSTED IN: ANIME SUMMARIES
    Action, Comedy <<<<<<<<<
    Information

    Genres: Action, Comedy
    Rating: (No Ratings Yet)

    Does anyone know a solution?

  9. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    my mistake :-(
    corrected below:

    function tags_in_post($atts) {    // [tags] outputs post's tags in a span
    global $post;
    $tags = '<span class="post-tags">';
    ob_start();
    the_tags( '<span class="post-tags">', ', ', '</span>' );
    $tags = ob_get_contents();
    ob_end_clean();
    return $tags;
    }
    add_shortcode ('tags', 'tags_in_post');

    http://php.net/manual/en/function.ob-start.php

  10. tjalling474
    Member
    Posted 3 years ago #

    It works =D

Topic Closed

This topic has been closed to new replies.

About this Topic