0

I want to display the taxonomies within the loop but with customized template.

Here is my code:

if ( have_posts() ) {
    while ( have_posts() ) {
        the_post();
        $args = array(
            'template' => '%s %l',
            'term_template' => '%2$s',
        ); 

        the_taxonomies($args);

The post is in the two categories: "Neues" and "Zweite". This code shows the post with the taxonomies like this:

"Kategorien Neues und Zweite"

how can I change the output like this:

"Neues, Zweite"

without the string "Kategorien" and another seperator "und"?

I tried the $arg = 'sep' => ', ' but this changes nothing.

Thx for help!

0

The simplest solution:

echo get_the_category_list( ', ' );

Following your way:

Change your $args like so:

$args = array(
        'template' => '%2$l',
        'term_template' => '%2$s',
); 

And then, add this to your functions.php file (this will affect all %l markers!);

add_filter( 'wp_sprintf_l', function($templates) {  
    // $templates['between_last_two'] = sprintf( __('%s, and %s'), '', '' );
    // $templates['between_only_two'] = sprintf( __('%s and %s'), '', '' );

    $templates['between_last_two'] = sprintf( '%s, %s', '', '' );
    $templates['between_only_two'] = sprintf( '%s, %s', '', '' );

    return $templates;
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.