使用CSS为搜索结果格式化div

时间:2012-02-13 17:23:44

标签: css html

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

<?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 id="A">
<div id="B">Post Results header & Post Results Code</div>
<div id="C">Page Results header & Page Results Code</div>
</div>

我在哪里插入div标签来完成此操作?谢谢!

1 个答案:

答案 0 :(得分:0)

这应该做你想要的:

<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>
相关问题