【问题标题】:Wordpress Function.php doesn't work where search.php when no results found找不到结果时,Wordpress Function.php 在 search.php 中不起作用
【发布时间】:2014-01-04 20:18:12
【问题描述】:

我正在开发一个自定义 Wordpress 网站,在博客部分我使用了小部件 Wordpress 侧边栏,当使用搜索小部件查找网站中存在的单词时,它工作正常,但是当我搜索丢失的单词时在站点中,侧边符,所有样式表和 JS 都不包括在内。在我看来,当搜索没有结果时,Wordpress 不会“运行”function.php

我发现了一个类似的问题:(wordpress sidebar loops wont work when in search.php when no results found)。

但是,即使我删除了if,它也不起作用,保持不变。

代码:

<div class="row" align="center" >
    <div class="container"> <div style="height: 60px;width: 100%"></div>    
        <h1 style="color: #087ba7;">Resulta da busca: <?php echo $s; ?></h1> 
    </div>
</div>

             <div class="row" align="center" >
                        <div class="container">
                            <div class="span9">
                                <?php if(have_posts()): 
                                        while(have_posts()): the_post(); ?>
                                            <div class="span9" style="text-align: left;margin-top: 50px;">
                                                <h1 style="font-size: 18.5px;"><?php the_title(); ?></h1> 
                                                <hr />
                                                <div class="span2 post_thumb div-img-circle">
                                                    <a href="<?php the_permalink(); ?>">
                                                        <?php echo the_post_thumbnail(); ?>
                                                    </a>
                                                </div>
                                                <div class="span6" style="text-align: justify;">
                                                    <a href="<?php the_permalink(); ?>" style="text-decoration: none;">

                                                        <?php the_excerpt(); ?>
                                                    </a>
                                                    <div style="width: 100%;text-align: right">
                                                        <a href="<?php the_permalink(); ?>">Leia Mais</a>  
                                                    </div>
                                                </div>
                                            </div>
                                <?php   endwhile; ?>
                                <?php else : ?>
                                    <?php wp_reset_query();?>
                                <div class="span9" style="text-align: left;margin-top: 50px;">
                                    <h1 style="font-size: 18.5px;"><?php echo wpautop( 'Sorry, no posts were found' ); ?></h1> 
                                </div>
                                <?php endif; ?>
                            </div>
                            <div class="span2" style="text-align: left;">
                                    <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?><?php endif; ?>
                            </div>
                        </div>
                    </div>


                    <div class="row" align="center" >
                        <div class="container"> 
                            <?php custom_pagination(); ?>
                        </div>
                    </div>

【问题讨论】:

  • 您需要提供更多信息。例如,您的代码的相关部分会有所帮助。
  • 对不起,我现在用代码编辑它

标签: php wordpress custom-wordpress-pages


【解决方案1】:

您的 else 语句很可能是问题所在。 wp_reset_query() 仅应在您必须根据 codex http://codex.wordpress.org/Function_Reference/wp_reset_query 使用 query_posts() 时使用。由于 query_posts 不在您显示的代码中,我认为这是问题所在。

【讨论】:

  • 我删除了它,但看起来还是一样,当搜索不返回任何结果时,function.php 不包括在内
  • 我做了一些测试,wordpress 没有在 标签中包含任何内容,我在 Dev 中编写了一些 Css,甚至将其导入到页面中
  • 我做了另一个更改,我评论了所有的 if,只留下一会儿,仍然有问题,当搜索一个不存在的单词时,它会丢失 中的所有代码
  • 我也删除了 While leave only
【解决方案2】:

我可以解决问题。 我复制了十二个主题文件夹并将我的自定义文件的内容复制到新文件夹中的相同文件中,它就可以工作了。

还是谢谢

【讨论】:

    猜你喜欢
    • 2012-12-28
    • 2021-12-01
    • 1970-01-01
    • 2022-11-10
    • 2011-05-29
    • 2022-01-16
    • 2011-05-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多