bcworkz on "Shortcode to display categories the post is listed under on the current post"

ساخت وبلاگ

Hi

Important note: Backup your site and use child themes instead of modifying the parent theme's code :)

Now that I've got that out of the way , here's a solution:

Add this to your functions.php

function get_cats(){
$categories = get_the_category();
$separator = ' ';
$output = '';
if ( ! empty( $categories ) ) { foreach( $categories as $category ) { $output .= '<a href="' . esc_url( get_category_link( $category->term_id ) ) . '" alt="' . esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ) . '">' . esc_html( $category->name ) . '</a>' . $separator; } echo trim( $output, $separator );
}}
add_shortcode('getcats', 'get_cats');

Then use [getcats] in your posts to display a list of categories the post is affiliated to.

All the best & happy coding!

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 163 تاريخ : دوشنبه 3 خرداد 1395 ساعت: 2:34