我已经创建了一个自定义搜索结果页面,该页面将关键字与类别、帖子、cpt匹配。。。
以下是类别的代码(它还显示了图像的类别ACF字段:
<?php
// post categories in results
$terms = get_terms( \'post\', array(
\'name__like\' => $s,
\'hide_empty\' => false // Optional
) );
?>
<?php
// list post categories in results
if ( count($terms) > 0 ) {
echo \'<div class="sr-categories">\';
echo \'<h3 class="search-title">Category results</h3>\';
?>
<div class="posts-wrap posts-layout-default row">
<?php
foreach ( $terms as $term ) { ?>
<?php
echo \'<article class="sub-cat-row col-md-4 col-sm-6 col-xs-6 col-xxs-12">\';
echo \'<a href="\' . esc_url( get_term_link( $term ) ) . \'" title="\' . esc_attr( $term->name ) . \'">\';
$taximg_id = get_field(\'image\', $term);
$taxsize = "grid-image"; // (thumbnail, medium, large, full or custom size)
$taximage = wp_get_attachment_image_src( $taximg_id, $taxsize );
if($taximg_id) { ?>
<img src="<?php echo $taximage[0]; ?>" alt="" class="img-responsive" />
<?php } else { ?>
<img src="<?php echo get_stylesheet_directory_uri(); ?>/assets/images/default-image-600x400.png" alt="" title="" />
<?php }
echo \'<div class="sc-title text-center">\' . esc_html( $term->name ) . \'</div></a>\';
echo \'</article>\';
//get_template_part(\'template-parts/loop/content\',\'listevents\');
wp_reset_postdata();
}
?>
</div>
<?php echo \'</div>\'; // eof sr-events
} else {
echo \'No Event categories found\';
}
?>