我最近发现,我们可以插入如下类别的下拉列表:
define( \'WP_USE_THEMES\', false );
require( \'./wp-load.php\' );
wp_dropdown_categories( array(
\'child_of\' => 0,
\'class\' => \'postform\',
\'depth\' => 0,
\'echo\' => 1,
\'exclude\' => \'\',
\'hide_empty\' => false,
\'hide_if_empty\' => false,
\'hierarchical\' => true,
\'id\' => \'\',
\'name\' => \'cat-dropdown\',
\'order\' => \'ASC\',
\'orderby\' => \'name\',
\'selected\' => 0,
\'show_count\' => 0,
\'show_option_all\' => \'\',
\'show_option_none\' => __(\'None\'),
\'tab_index\' => 0,
\'taxonomy\' => \'format\',
) );
这很好,但是如果我想选择多个类别呢?
我遇到过wp_category_checklist()
并尝试了以下代码:
function wp_category_checklist(
$post_id = 0,
$descendants_and_self = 0,
$selected_cats = false,
$popular_cats = false,
$walker = null,
$checked_ontop = true
) {
wp_terms_checklist( $post_id, array(
\'taxonomy\' => \'category\',
\'descendants_and_self\' => $descendants_and_self,
\'selected_cats\' => $selected_cats,
\'popular_cats\' => $popular_cats,
\'walker\' => $walker,
\'checked_ontop\' => $checked_ontop
) );
}
但它没有输出任何东西。
我试图在空白页上获得我的类别列表,而不是在侧边栏或帖子中。这可能吗?
SO网友:Shapon Pal
如果要使用复选框选择多个自定义分类法。您可以使用该代码。。
$html .= wp_dropdown_categories( array(
\'taxonomy\' => \'taxonomy_name\',
\'hierarchical\' => 0,
) );
$html = str_replace( "form id=", "form multiple=\'multiple\' id=", $html );
$html = str_replace( "select", "span", $html );
$html = str_replace( "option class=", "input type=\'checkbox\' class=", $html );
$html = str_replace( "option", "", $html );
$html = str_replace( "</>", "<br/>", $html );
echo $html;
如果要使用复选框选择多个类别。您可以使用该代码。。
$html = wp_dropdown_categories( array( \'echo\' => 0, \'hierarchical\' => 0 ) ); // Your Query here
$html = str_replace( "form id=", "form multiple=\'multiple\' id=", $html );
$html = str_replace( "select", "span", $html );
$html = str_replace( "option class=", "input type=\'checkbox\' class=", $html );
$html = str_replace( "option", "", $html );
$html = str_replace( "</>", "<br/>", $html );
echo $html;