【问题标题】:Search bar in duplicate (wordpress/php/bootstrap)搜索栏重复(wordpress/php/bootstrap)
【发布时间】:2017-11-22 16:15:36
【问题描述】:

由于某种原因,我得到了重复的搜索栏。 我怀疑我在某处有一个双重功能命令......但我找不到它。有人可以用“新鲜的眼睛”看代码并尝试找出我的错误吗? 因为 wordpress 不断给我 2 个搜索栏而不是一个 我正在使用 Notepad++、Bootstrap v 3.0 和 Wordpress 4.7.8

这里是代码

<?php get_header(); ?>

<div class="row">

    <div class="col-xs-12 col-sm-8">

        <div class="row text-center no-margin">

        <?php 
        $currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array('posts_per_page' => 3,'post_type'=>'post', 'paged' => $currentPage);
        new WP_Query($args);
        if( have_posts() ): $i = 0;

            while( have_posts() ): the_post(); ?>

                <?php 
                    if($i==0): $column = 12; $class = '';
                    elseif($i > 0 && $i <= 2): $column = 6; $class = ' second-row-padding';
                    elseif($i > 2): $column = 4; $class = ' third-row-padding';
                    endif;

                ?>
                    <?php the_content(); ?>

                    <div class="col-xs-<?php echo $column; echo $class; ?> blog-item">
                        <?php if( has_post_thumbnail() ):
                            $urlImg = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
                        endif; ?>
                        <div class="blog-element" style="background-image: url(<?php echo $urlImg; ?>);">

                            <!--<?php the_title( sprintf('<h1 class="entry-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h1>' ); ?> -->
                             <h1 class="entry-title"><?php the_title(); ?></h1>

                            <small><?php the_category(' '); ?></small>
                        </div>
                    </div>

            <?php $i++; endwhile; ?>

            <div class="col-xs-6 text-left">
                <?php next_posts_link('« Older Posts'); ?>
            </div>
            <div class="col-xs-6 text-right">
                <?php previous_posts_link('Newer Posts »'); ?>
            </div>

        <?php endif;
                wp_reset_query();
        ?>
        </div>

    </div>

    <div class="col-xs-12 col-sm-4">
        <?php get_sidebar(); ?>
    </div>

</div>

<?php get_footer(); ?>

【问题讨论】:

  • 您的代码似乎缺少部分(并且没有真正格式化)。顺便问一下,您使用的是什么模板(如果是您自定义的,请包括调用搜索栏的部分)?
  • 是的,我正在使用自定义模板。该代码来自我的 index.php,我知道它是“模板的核心”
  • 是的,这段代码应该只显示一个搜索栏,我在你的index.php 中没有看到它,你是否在模板文件的任何地方添加了这段代码(搜索栏之一)?侧边栏中应该默认有一个,如果我没记错的话(sidebar.php,但取决于模板的基础是什么),如果你添加了一个,它可能会重复。还要检查您是否没有在某处包含searchform.php,这也会添加此表单
  • 我看不到搜索栏在您的代码中的任何位置输出。如果搜索栏在标题中,您需要向我们展示header.php 文件的 HTML/PHP。

标签: php wordpress twitter-bootstrap duplicates notepad++


【解决方案1】:

试试这个代码。

我已禁用//get_sidebar();

        <?php get_header(); ?>

<div class="row">

    <div class="col-xs-12 col-sm-8">

        <div class="row text-center no-margin">

        <?php 
        $currentPage = (get_query_var('paged')) ? get_query_var('paged') : 1;
        $args = array('posts_per_page' => 3,'post_type'=>'post', 'paged' => $currentPage);
        new WP_Query($args);
        if( have_posts() ): $i = 0;

            while( have_posts() ): the_post(); ?>

                <?php 
                    if($i==0): $column = 12; $class = '';
                    elseif($i > 0 && $i <= 2): $column = 6; $class = ' second-row-padding';
                    elseif($i > 2): $column = 4; $class = ' third-row-padding';
                    endif;

                ?>


                    <div class="col-xs-<?php echo $column; echo $class; ?> blog-item">
                        <?php if( has_post_thumbnail() ):
                            $urlImg = wp_get_attachment_url( get_post_thumbnail_id( get_the_ID() ) );
                        endif; ?>
                        <div class="blog-element" style="background-image: url(<?php echo $urlImg; ?>);">

                            <!--<?php the_title( sprintf('<h1 class="entry-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h1>' ); ?> -->
                             <h1 class="entry-title"><?php the_title(); ?></h1>

                             <?php the_content(); ?>

                            <small><?php the_category(' '); ?></small>
                        </div>
                    </div>

            <?php $i++; endwhile; ?>

            <div class="col-xs-6 text-left">
                <?php next_posts_link('« Older Posts'); ?>
            </div>
            <div class="col-xs-6 text-right">
                <?php previous_posts_link('Newer Posts »'); ?>
            </div>

        <?php endif;
                wp_reset_query();
        ?>
        </div>

    </div>

    <div class="col-xs-12 col-sm-4">
        <?php //get_sidebar(); ?>
    </div>

</div>

【讨论】:

  • 很高兴为您提供帮助。您之前的问题屏幕截图有助于找出问题。
猜你喜欢
  • 2013-10-17
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 2019-03-24
  • 2018-02-03
  • 1970-01-01
相关资源
最近更新 更多