JSFiddle - React, Tailwind, and code Playground
JavaScript
function test($attr) {
extract(shortcode_atts(array(
'type' => 'cat'
), $attr));
/*
terms_return_value
term_id int ID
name string 名前
slug string スラッグ
term_group int グループID
term_taxonomy_id int タクソノミーID
taxonomy string タクソノミー名
description string 説明
parent int 親タクソノミーのID。親タクソノミーがない場合は0となる
count int 投稿数
*/
$out = "";
$out .= $type;
$out .= "<ul>";
switch($type){
case "cat":
$cats = get_terms( 'category', 'get=all' );
foreach($cats as $cat){
$out .= "<li><a href='". get_category_link( $cat->term_id ) ."'>". $cat->name ."</a></li>";
}
break;
case "tag":
$tags = get_tags();
foreach($tags as $tag){
$out .= "<li><a href='". get_tag_link( $tag->term_id ) ."'>". $tag->name ."</a></li>";
}
break;
default:
$dat = get_terms( 'category', 'get=all' );
foreach($dat as $dt){
$out .= "<li><a href='". get_category_link( $dt->term_id ) ."'>". $dt->name ."</a></li>";
}
}
$out .= "</ul>";
return $out;
}
add_shortcode('getterm', 'test');