【问题标题】:I want the search results to appear in columns, but only the text does我希望搜索结果出现在列中,但只有文本出现
【发布时间】:2016-08-06 00:25:26
【问题描述】:

我有一个发布搜索结果的 WP 插件。这是php的结果:

<?php
/**
 * Search & Filter Pro 
 *
 * Sample Results Template
 * 
 * @package   Search_Filter
 * @author    Ross Morsali
 * @link      http://www.designsandcode.com/
 * @copyright 2015 Designs & Code
 * 
 * Note: these templates are not full page templates, rather 
 * just an encaspulation of the your results loop which should
 * be inserted in to other pages by using a shortcode - think 
 * of it as a template part
 * 
 * This template is an absolute base example showing you what
 * you can do, for more customisation see the WordPress docs 
 * and using template tags - 
 * 
 * http://codex.wordpress.org/Template_Tags
 *
 */


if ( $query->have_posts() )
{

    ?>

    Found <?php echo $query->found_posts; ?> Results<br />
    Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />


    <div class="pagination">

        <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
        <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
        <?php
            /* example code for using the wp_pagenavi plugin */
            if (function_exists('wp_pagenavi'))
            {
                echo "<br />";
                wp_pagenavi( array( 'query' => $query ) );
            }
        ?>
    </div>

    <?php
    while ($query->have_posts())
    {
        $query->the_post();

        ?>

<div>
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php 
                if ( has_post_thumbnail() ) {
                    echo '<p>';
                    the_post_thumbnail("small");
                    echo '</p>';
                }
            ?>
            <p><br /><?php the_excerpt(); ?><p>
</div>

        <?php
    }
    ?>
    Page <?php echo $query->query['paged']; ?> of <?php echo $query->max_num_pages; ?><br />

    <div class="pagination">

        <div class="nav-previous"><?php next_posts_link( 'Older posts', $query->max_num_pages ); ?></div>
        <div class="nav-next"><?php previous_posts_link( 'Newer posts' ); ?></div>
        <?php
            /* example code for using the wp_pagenavi plugin */
            if (function_exists('wp_pagenavi'))
            {
                echo "<br />";
                wp_pagenavi( array( 'query' => $query ) );
            }
        ?>
    </div>
    <?php
}
else
{
    echo "No Results Found";
}

?>

现在我希望结果(帖子)出现在 2 列中,但是,当我尝试这样做时:

<div class="container">
    <div class="row">
        <div class="col-md-2">
            <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
            <?php 
                if ( has_post_thumbnail() ) {
                    echo '<p>';
                    the_post_thumbnail("small");
                    echo '</p>';
                }
            ?>
            <p><br /><?php the_excerpt(); ?><p>
</div>
</div>
</div>

我可以看到文本 (p) 出现在列中,但不是结果。

我究竟如何实现我的目标?

【问题讨论】:

  • 由于某种原因它没有保存我的编辑。我已经编辑了它,原始答案中的第二段代码是错误的。
  • 这是我得到的结果:prntscr.com/as53eg 我希望帖子结果本身排列成列,而不是文本。
  • 另外,由于某种原因,它甚至只在一篇文章的文本上放置了列,而不是所有文章:prntscr.com/as53xu

标签: php html css wordpress twitter-bootstrap-3


【解决方案1】:

有几个错误。 首先col-md-2 在 12 列布局中创建 2 列宽的 div。所以这是六分之一,而不是一半。应该是col-md-6

接下来的问题是为每个帖子添加一个容器、行和列。但是你应该只有 1 个容器和 1 行。对于每个帖子,您应该将列设为 div。

<!-- 1 container and row -->
<div class="container">
<div class="row">    
<?php
  while ($query->have_posts()){
    $query->the_post();
?>
    <!-- a six column wide div for each post -->
    <div class="col-md-6">
      <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
      <?php 
        if ( has_post_thumbnail() ) {
          echo '<p>';
            the_post_thumbnail("small");
          echo '</p>';
        }
      ?>
      <p><br /><?php the_excerpt(); ?><p>
  </div>

<?php
  }
?>
</div>
</div>

【讨论】:

  • 做到了!感谢您的帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-05-10
  • 1970-01-01
  • 1970-01-01
  • 2020-07-09
相关资源
最近更新 更多