我正在将Html转换为Wordpress。我可以通过
<?php get_search_form( $echo ); ?>
但如果通过搜索找不到任何数据,我想显示未找到的内容。我该怎么做,有什么帮助吗?我正在将Html转换为Wordpress。我可以通过
<?php get_search_form( $echo ); ?>
但如果通过搜索找不到任何数据,我想显示未找到的内容。我该怎么做,有什么帮助吗?在您的index.php
, 你应该有点像:
<?php if ( have_posts() ) : ?>
<!-- HTML -->
<?php while ( have_posts() ) : the_post() ?>
<!-- Post content -->
<?php endwhile ?>
<!-- HTML -->
<?php endif ?>
您可以将此代码扩展为“如果没有帖子并且正在搜索,则显示消息”:<?php if ( have_posts() ) : ?>
<!-- HTML -->
<?php while ( have_posts() ) : the_post() ?>
<!-- Post content -->
<?php endwhile ?>
<!-- HTML -->
<?php elseif ( is_search() ) : ?>
<!-- No posts and is search, show message -->
<?php endif ?>
我想添加一个自定义字段(“introduction”和“ensavoirplus”)来搜索Wordpress,但SQL代码并不精确。我不明白我是否犯了错误,或者WP不能做到这一点。但我的尝试失败了。。。我不知道为什么,因为我完全按照抄本上说的去做。这是我的代码:function recherche_avancee( $query ) { if ( !is_admin() && $query->is_search ) { $custom_fiel