【问题标题】:Search result return "random number" with search query搜索结果返回带有搜索查询的“随机数”
【发布时间】:2020-07-24 02:11:28
【问题描述】:

我正在开发一个 wordpress 主题。 搜索引擎用我的查询搜索词返回一个数字。

例如:搜索词“lorem ipsum” 标题搜索结果--->搜索结果:“lorem ipsum47”

我试图寻找问题,我不确定,但这里有我在谈论的代码:

   <h2 class="title-page page-title">
                            <?php if ( is_home() ) :
                                if ( is_front_page() ):
                                    esc_html_e( 'Latest Posts', 'cize' );
                                else:
                                    single_post_title();
                                endif;
                            elseif ( is_page() ):
                                single_post_title();
                            elseif ( is_search() ):
                                echo printf( esc_html__( 'Search Results for: %s', 'cize' ), '<span>' . get_search_query() . '</span>' );
                            else:
                                the_archive_title();
                            endif; ?>
                        </h2>

另一点可能有所帮助的是经过研究后在线显示的 HTML:

<div class="container">
        <h2 class="title-page page-title">
                            Search result for: <span>lorem ipsum</span>47                            </h2>
                                                                </div>

问题可能出在这部分代码上????

else:
    the_archive_title();
endif; ?>

感谢您的宝贵时间 里卡多

【问题讨论】:

    标签: php wordpress search wordpress-theming


    【解决方案1】:

    printf 有时候有点棘手

    更改is_search 部分,而不是echo printf 使用简单的echo,如下所示。

    <h2 class="title-page page-title">
        <?php if ( is_home() ) :
            if ( is_front_page() ):
                esc_html_e( 'Latest Posts', 'cize' );
            else:
                single_post_title();
            endif;
        elseif ( is_page() ):
            single_post_title();
        elseif ( is_search() ):
            echo 'Search Results for: '.get_search_query();
        else:
            the_archive_title();
        endif; ?>
    </h2>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 2021-02-10
      • 1970-01-01
      相关资源
      最近更新 更多