add_shortcode( 'categorytags', 'tfc_tags_for_category_shortcode' );
function tfc_tags_for_category_shortcode( $atts, $content, $tag ){
//example : [categorytags cat="entertainment"/]
$inst = shortcode_atts(
array(
'cat' => ''
),
(array)$atts,
$tag
);
$html = '';
//no category, no results...
if( !empty( $inst['cat'] ) ){
//get the category...
if( is_numeric( $inst['cat'] ) ){
$cat = get_term_by( 'id', intval( $inst['cat'] ), 'category' );
}else{
$cat = get_term_by( 'slug', $inst['cat'], 'category' );
}
if( !empty( $cat ) ){
//get the posts in the category...
$postids = get_objects_in_term( $cat->term_id, 'category' );
if( !is_wp_error( $postids ) && !empty( $postids ) ){
//get the tags for the posts...
$tags = wp_get_object_terms( (array)$postids, 'post_tag' );
if( !is_wp_error( $tags ) && !empty( $tags ) ){
//make a link for each tag...
foreach( $tags as $tag ){
//simple paragraph containing linked tag name...
$html .= '' . $tag->name . '
';
}
}
}
}
}
return $html;
}
?>
404 :(
पृष्ठ उपलब्ध छैन
सायद हामी यो पेजमा काम गर्दै छौँ होला। केही क्षणमा पुनः प्रयास गर्नुहोस्।.
Back to top button