• Resolved korg007

    (@gillesgagnon)


    Hi Support!

    Thanks for the fantastic plugin! I use it with a client to display random posts in a specific category.

    We need to display the the tags associated with the post displayed. We’d like this list of tags to appear below the title.

    Can you steer us in the right direction please?

    We look forward to hearing from you,

    Cheers!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Bill Erickson

    (@billerickson)

    Despite its name, you can actually use the category_display parameter to display any taxonomy.

    If you just set it to “true” it will display categories:

    [display-posts category_display="true"]

    Instead of “true”, you can specify the taxonomy you want to use.

    So in your case, you would use:

    [display-posts category_display="post_tag"]
    Thread Starter korg007

    (@gillesgagnon)

    Thanks, Bill!

    Much appreciate the quick response. It’s very close now and needs a bit of formatting.

    We need:

    1. For the string: “Posted in:” to be changed to “Themes: ”
    2. For the string above to be positioned below the title. The code appears to position the code inline (to the right) of the title… on the same line as the title.

    We’d love your advice on the above.
    Cheers!

    Plugin Author Bill Erickson

    (@billerickson)

    You can customize the string using the category_label parameter. Ex:

    [display-posts category_display="post_tag" category_label="Themes: "]

    You can use CSS to adjust the styling of the output. Ex:

    .display-posts-listing .category-display { display: block; }
    Thread Starter korg007

    (@gillesgagnon)

    Thanks Bill!
    Worked like a charm!

    Off I go to rate your work/plugin 5 stars. (EDIT: LOL… I had already reviewed) ??

    Superb plugin AND support!
    Cheers!

    • This reply was modified 1 year, 7 months ago by korg007.
    Thread Starter korg007

    (@gillesgagnon)

    Hi Bil,

    Not sure if this possible but thought I’d ask. I reviewed the documentation but came empty-handed.

    In the list of tags that’s generated, my client is asking if it’s possible to replace the comma character (“,”) separating the tags, with the pipe command “|”?

    Plugin Author Bill Erickson

    (@billerickson)

    There’s no shortcode parameter for managing that separator.

    If you’re confident that none of the tags will contain a “,” character in their name, you could find/replace the “,” with a “|” in that section with this code in your theme’s functions.php file or a Code Snippets plugin:

    add_filter( 
    	'display_posts_shortcode_category_display',
    	function( $output ) {
    		return str_replace( ',', ' |', $output );
    } );

    A safer option wold be to use that filter to completely rebuild the output.

    Thread Starter korg007

    (@gillesgagnon)

    Thanks Bill.

    What do you mean by “A safer option wold be to use that filter to completely rebuild the output.”?

    Plugin Author Bill Erickson

    (@billerickson)

    The code above will find/replace any instance of “,” in the text string, not just separators. So if you had a tag called “Hiking, Fishing & Outdoors”, the output on the page would be “Hiking | Fishing & Outdoors”.

    Instead of doing the find/replace, you could actually rebuild the entire output using the separator you want. Ex:

    add_filter(
    'display_posts_shortcode_category_display',
    function( $output, $terms, $category_display, $atts ) {
    
    $term_output = [];
    foreach( $terms as $term ) {
    	$term_output[] = '<a href="' . get_term_link( $term, $category_display ) . '">' . $term->name . '</a>';
    }
    
    $category_label = isset( $atts['category_label'] ) ? $atts['category_label'] : 'Posted in: ';
    
    return ' <span class="category-display"><span class="category-display-label">' . $category_label . '</span> ' . implode( ' | ', $term_output ) . '</span>';
    
    }, 10, 4 );

    Note: this code is untested, I just wrote it here in the comment. If it doesn’t work, hopefully it gives you the general idea.

    Thread Starter korg007

    (@gillesgagnon)

    I see. I like this approach. Thanks so much. This is very helpful.

    Where would I find the original code to compare as I build … to ensure I’m using the correct syntax?

    Plugin Author Bill Erickson

    (@billerickson)

    Thread Starter korg007

    (@gillesgagnon)

    Perfect! Thansks. So appreciated.
    I should be good to go.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘How to display Taga belonging to post?’ is closed to new replies.