dongmu5815 2013-08-22 17:14
浏览 43

如何在这个PHP代码中插入div

I am listing my posts alphabetically, on top of each section I am displaying the initial letter and the php code is this

<?php
        $args=array(
          'post_type' => 'books',
          'orderby' => 'title',
          'order' => 'ASC',
          'posts_per_page'=>-1,
          'caller_get_posts'=>1
        );
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          while ($my_query->have_posts()) : $my_query->the_post();?>
            <?php
            $this_char = strtoupper(substr($post->post_title,0,1));
            if ($this_char != $last_char) {
              $last_char = $this_char;
              echo '<h3>'.$last_char.'</h3>';

            } ?>
            <p><a data-transition="slide" href="<?php the_permalink() ?>"     rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
            <?php endwhile; } 
        wp_reset_query();
    ?>

with and HTML output of

<div class="entry-content">
<h3>A</h3>
<p></p>
<p></p>
<p></p>
<p></p>
<h3>B</h3>
<p></p>
<p></p>
<p></p>
</div>

Now my problem is that I need to insert a div with a data-role of collapsible so it can look like

<div class="entry-content">
<div dat-role="collapsible">
    <h3>A</h3>
    <p></p>
    <p></p>
    <p></p>
    <p></p>
</div>
<div dat-role="collapsible">
    <h3>B</h3>
    <p></p>
    <p></p>
    <p></p>
    <p></p>
</div>
</div>

but I can't. I have tried to echo out the before the h3 and after the if but it doesn't get me the markup I need. Any help?

  • 写回答

2条回答 默认 最新

  • dskld5423 2013-08-22 17:18
    关注
    <?php
            $args=array(
              'post_type' => 'books',
              'orderby' => 'title',
              'order' => 'ASC',
              'posts_per_page'=>-1,
              'caller_get_posts'=>1
            );
            $my_query = new WP_Query($args);
            if( $my_query->have_posts() ) {
              while ($my_query->have_posts()) : $my_query->the_post();?>
                <?php
                $this_char = strtoupper(substr($post->post_title,0,1));
                if ($this_char != $last_char) {
                  $last_char = $this_char;
                  echo '<div dat-role="collapsible"><h3>'.$last_char.'</h3>';
    
                } ?>
                <p><a data-transition="slide" href="<?php the_permalink() ?>"     rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
                <?php endwhile; } 
                echo "</div>";
            wp_reset_query();
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题