dongyuxiao6295 2014-04-14 12:21
浏览 46
已采纳

如何在wordpress中每5个帖子后添加任何文本框

I have updated 20 posts in wordpress theme. And i need to add my own text box after every 5 posts. So that i can add 4 text box after every 5 post. I think it can be done by $post_counter please any one give me a query for my question.

My code simply seems to,

<?php
query_posts( array('posts_per_page'=>20,orderby=>post_date, order=>desc) );
while ( have_posts() ) : the_post();
?>
<?php the_title(); ?>
<?php the_post_thumbnail(); ?>
<?php endwhile; ?>
  • 写回答

4条回答 默认 最新

  • dtlc84438 2014-04-14 13:02
    关注

    I read your comment and i updated @zameerkhan code.

    <?php
    $query = new WP_Query( array('posts_per_page' => 20, orderby => post_date, order => desc) );
    $p = 1;
    while ( $query->have_posts() ) : $query->the_post();
    ?>
    <?php the_title(); ?>
    <?php the_post_thumbnail(); ?>
    //this will create text box after 5 post with name mytext1,mytext2 etc.
    <?php echo ($p%5 == 0) ? '<input type="text" name="mytext'.($p/5).'" />': "";
    $p++;
    ?>
    <?php endwhile; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站