如何在WordPress中禁用空白搜索的WP页导航

时间:2018-12-29 作者:Rajesh Patel

enter image description here

Im在搜索中使用以下代码。php

<?php if (have_posts() && strlen( trim(get_search_query()) ) != 0 ) : while (have_posts()) : the_post(); ?>

<?php endwhile; else:?> <b>No results match your search.</b> <p>For Accurate results, Please Search the Model Number of the device or the Brand Name.</p> <?php endif; ?>

<div class="navigation"><?php if(function_exists(\'wp_pagenavi\')) { wp_pagenavi(); } else { ?> <?php } ?></div>
功能。php:

function SearchFilter($query) {
    // If \'s\' request variable is set but empty
    if (isset($_GET[\'s\']) && empty($_GET[\'s\']) && $query->is_main_query()){
        $query->is_search = true;
        $query->is_home = false;
    }
    return $query;}
add_filter(\'pre_get_posts\',\'SearchFilter\');
如何在黑色搜索中禁用导航?

1 个回复
SO网友:Debabrata Karfa

你能在搜索时试试这个吗。php

<?php if ( have_posts() && strlen( trim( get_search_query() ) ) != 0 ) : while ( have_posts() ) : the_post();  // Start of the loop.?>
    <?php  // Do code for the loop. ?>
<?php endwhile;  // End of the loop. ?>
    <div class="navigation">
        <?php 
            if( function_exists( \'wp_pagenavi\' ) ) { 
                wp_pagenavi(); 
            }
        ?>
    </div>
<?php else:?> 
    <b>No results match your search.</b> 
    <p>For Accurate results, Please Search the Model Number of the device or the Brand Name.</p> 
<?php 
endif; 
?>