Support » Fixing WordPress » How to show tags IN a post?

  • 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?

Viewing 9 replies - 1 through 9 (of 9 total)
  • 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.

    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

    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

    Thanks a lot 😀
    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?

    @tjalling474

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

    Thanks a lot. It works perfect now! =D

    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?

    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

    It works =D

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘How to show tags IN a post?’ is closed to new replies.