解决了难看的问题,但有效。过滤器的一般形式:
<?php
add_filter(\'term_link\', function ($termlink, $term, $taxonomy) {
if (\'CPT-TAXONOMY-NAME\' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . \'?FACETWP-FACET-NAME=\' . $term->slug;
}
return $termlink;
}, 10, 3);
功能中的功能。php:
<?php
function list_hierarchical_terms($taxonomy) {
global $post;
$terms = wp_get_post_terms( $post->ID, $taxonomy, array( "fields" => "ids" ) );
if( $terms ) {
echo \'<?ul>\';
$terms = trim( implode( \',\', (array) $terms ), \' ,\' );
wp_list_categories( \'title_li=&taxonomy=\' . $taxonomy . \'&include=\' . $terms );
echo \'<?/ul>\';
}
}
现在我不知道如何把它写得更简单。filter in函数的函数。php:
<?php
function termlink_transformation_freuciv_post_type($termlink, $term, $taxonomy)
{
if (\'freuciv_post_type\' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . \'?fwp_typ=\' . $term->slug;
}
return $termlink;
}
function termlink_transformation_category($termlink, $term, $taxonomy)
{
if (\'category\' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . \'?fwp_categories=\' . $term->slug;
}
return $termlink;
}
function termlink_transformation_hierarchical_tags($termlink, $term, $taxonomy)
{
if (\'hierarchical_tags\' == $taxonomy) {
$termlink = trailingslashit(get_home_url()) . \'?fwp_tags=\' . $term->slug;
}
return $termlink;
}
在模板部分:
<?php
add_filter(\'term_link\', \'termlink_transformation_freuciv_post_type\', 10, 3);
list_hierarchical_terms(\'freuciv_post_type\', \'<h5 style="margin-bottom: 5px">Typ: </h5>\');
remove_filter( \'term_link\', \'termlink_transformation_freuciv_post_type\', 10 );
add_filter(\'term_link\', \'termlink_transformation_category\', 10, 3);
list_hierarchical_terms(\'category\', \'<h5 style="margin-bottom: 5px; margin-top: 10px;">Kategorien: </h5>\');
remove_filter( \'term_link\', \'termlink_transformation_category\', 10 );
add_filter(\'term_link\', \'termlink_transformation_hierarchical_tags\', 10, 3);
list_hierarchical_terms(\'hierarchical_tags\', \'<h5 style="margin-bottom: 5px; margin-top: 10px;">Tags: </h5>\');
remove_filter( \'term_link\', \'termlink_transformation_hierarchical_tags\', 10 );
这里重复太多了。我不知道如何简化它。