我正在尝试使用is\\u search从函数中输出一些内容。php。我在实际搜索页面本身上使用is\\U搜索,效果很好:
if(is_search()) {
echo get_search_query( \'<h1>\', \'</h1>\' );
}
但从功能上来说。php这不起作用:
function data_scroll_all(){
if(is_search()) {
$offset = $_POST[\'offset\'];
$category = $_POST[\'cat\'];
$args = array(\'posts_per_page\' => 3, \'category__not_in\' => 1, \'offset\' => $offset, \'orderby\' => \'date\', \'cat\' => $category);
$loop = new WP_Query($args);
if($loop->have_posts()) {
while($loop->have_posts()){
$loop->the_post();
get_template_part( \'content-archive\' );
}
} wp_reset_postdata();
} else {
echo "Nope!";
}
die(\'\');
}
有了这个,我只会说“不!”当我在搜索页面上时。
我的搜索模板设置如下:
<?php
/*
Template Name: Search Page
*/
?>
<?php
global $query_string;
$query_args = explode("&", $query_string);
$search_query = array();
foreach($query_args as $key => $string) {
$query_split = explode("=", $string);
$search_query[$query_split[0]] = urldecode($query_split[1]);
} // foreach
$search = new WP_Query($search_query);
?>
我有一个航路点“无限滚动”功能,到达页面底部时触发:
var ajax_url = $(\'.loadAll\').attr(\'data-url\');
var cat = $(\'.loadAll\').attr(\'data-cat\');
var offset = -3;
$(\'#infinite-load\').waypoint(function (direction) {
if (direction === \'down\') {
offset = parseInt(offset) + 3;
$.ajax({
dataType: "HTML",
url: ajax_url,
type: \'POST\',
data: {
action: \'data_scroll_all\',
cat: cat,
offset: offset
},
beforeSend: function () {
$(".loading").show(); //show image loading
},
success: function (data) {
$(".loading").hide();
$(\'#infinite-load\').append(data);
$.waypoints(\'refresh\');
}
});
}
}, {
offset: \'bottom-in-view\'
});