自定义搜索Wordpress不再起作用

时间:2018-02-23 09:38:19

标签: php wordpress search

前一段时间(大约半年),我收到了一个代码,用于自定义客户的搜索页面。网站/页面Tiantu-Mineralen Mineralen Gids。我制作了一份Wordpress'在我的子主题文件夹中搜索页面。然后,所有搜索结果都显示在彼此之下(仅标题,缩略图和摘录)。现在,几个月后我再次搜索(在' ame' - 搜索amethists),但我只得到1个结果。

我自己尝试编辑但没有成功.. 我现在的代码是:

<?php if ( have_posts() ) { ?>
    <?php while ( have_posts() ) { the_post(); ?>
        <div class="thumbsearch"><?php  the_post_thumbnail('small') ?></div>
        <div class="searchinfo"><h3><a href="<?php echo get_permalink(); ?>">
            <?php search_title_highlight(); ?>
        </a></h3>

        <?php echo substr(search_excerpt_highlight(),''); ?>
        <div class="h-readmore"> <a href="<?php the_permalink(); ?>">Read More</a></div>
        </div>

    <?php } ?>

我试图删除:

 <?php echo substr(search_excerpt_highlight(),''); ?>
 <div class="h-readmore"> <a href="<?php the_permalink(); ?>">Read More</a></div>

我得到了更多结果,但它非常混乱。

My Custom Functions.php具有以下代码:

function search_excerpt_highlight( $limit ) {
$excerpt = get_the_excerpt();
$excerpt = explode(' ', get_the_excerpt(), $limit);

if ( count( $excerpt ) >= $limit ) {
    array_pop( $excerpt );
    $excerpt = implode(' ', $excerpt);
} else {
    $excerpt = implode(' ', $excerpt);
}

$excerpt = apply_filters( 'get_the_excerpt', $excerpt );

$allowed_tags = '<p>,<br>,<mark>';
$excerpt = strip_tags( $excerpt, $allowed_tags );

$excerpt = preg_replace('`\[[^\]]*\]`', '', $excerpt);

$keys = implode('|', explode(' ', get_search_query()));
$excerpt = trim(preg_replace('/(' . $keys .')/iu', '<mark class="search-
highlight">\0</mark>', $excerpt));

echo '<p>' . $excerpt . ' ...</p>';
}

function search_title_highlight() {
$title = get_the_title();
$keys = implode('|', explode(' ', get_search_query()));
$title = preg_replace('/(' . $keys .')/iu', '<strong class="search-
highlight">\0</strong>', $title);

echo $title;
}

function search_content_highlight($limit) {
    $content = get_the_content();
    $keys = implode('|', explode(' ', get_search_query()));
    $content = preg_replace('/(' . $keys .')/iu', '<strong class="search-
highlight">\0</strong>', $content);

    echo '<p>' . $content . '</p>';
}

你们有解决方案吗?!

提前致谢!

0 个答案:

没有答案