【问题标题】:formatting divs using CSS for Search Results使用 CSS 为搜索结果格式化 div
【发布时间】:2015-12-29 21:26:00
【问题描述】:

以下是搜索结果的代码。搜索将页面结果与帖子结果分开。

<?php
    foreach (array('post','page') as $pt) :
        $search_query = new WP_Query(array(
                'post_type'         => $pt,
                's'                 => $s,
                'posts_per_page'    => 10,
                'paged'             => $paged
            )
        );
    ?>
    <?php if ($pt == 'post') : ?>
        <h2 class="pagetitle">Post Search Results</h2>
    <?php else : ?>
        <h2 class="pagetitle">Page Search Results</h2>
    <?php endif; ?>
    <?php 
        if ($search_query->have_posts()) : while ($search_query->have_posts()) :         $search_query->the_post();
        if ($pt == 'post') :
    ?>
        Post Results Code
    <?php else : ?>
        Page Results Code
    <?php endif; ?>
    <?php endwhile; else : ?>
        No Results
    <?php endif; ?>
<?php endforeach; ?>

使用当前代码,如果没有找到任何帖子/页面搜索结果的搜索结果,则短语 "No Results" 将显示在帖子/页面结果标题下方。这需要保留。

我想将标题 "Post Search Results""Post Results Code" 放在一个 div 中,将标题 "Page Search Results""Page Results Code" 放在单独的 div 中,该 div 设置在另一个 div 中。像这样:

<div id="A">
<div id="B">Post Results header & Post Results Code</div>
<div id="C">Page Results header & Page Results Code</div>
</div>

我应该在代码中的何处插入 div 标签来完成此操作?谢谢!

【问题讨论】:

    标签: css html


    【解决方案1】:

    这应该做你想做的:

    <div id="A">
    <?php
    foreach (array('post','page') as $pt) :
        $search_query = new WP_Query(array(
                'post_type'         => $pt,
                's'                 => $s,
                'posts_per_page'    => 10,
                'paged'             => $paged
            )
        );
    ?>
    <?php if ($pt == 'post') : ?>
        <div id="B">
        <h2 class="pagetitle">Post Search Results</h2>
    <?php else : ?>
        <div id="C">
        <h2 class="pagetitle">Page Search Results</h2>
    <?php endif; ?>
    <?php 
        if ($search_query->have_posts()) : while ($search_query->have_posts()) :         $search_query->the_post();
        if ($pt == 'post') :
    ?>
        Post Results Code
    <?php else : ?>
        Page Results Code
    <?php endif; ?>
    <?php endwhile; else : ?>
        No Results
    <?php endif; ?>
    </div>
    <?php endforeach; ?>
    </div>
    

    【讨论】:

    • 我遇到了一个错误。 div.B 和 div.C 的
      标签在哪里?
  • 我在拼写错误中删除了最后两行。立即尝试。
  • 猜你喜欢
    • 1970-01-01
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多