dqc3469 2015-11-28 05:00
浏览 33

Wordpress在帖子之间添加单独的部分,而不会影响帖子的连续性

I am building a basic Wordpress blog which is build on Duplex theme. I Would like to do some minor customization to the site where in the site has an Instagram widget after two posts and then continue the posts.

Just to simplify the order of the page would be :

  1. 2 posts.
  2. Instagram widget
  3. Continue from 3rd post.

The Front page displays set to posts like the way I want.

How can I achieve getting the Instagram widget in between of the posts without disturbing the flow?

  • 写回答

3条回答 默认 最新

  • douhui0975 2015-11-28 06:39
    关注

    What you do is run the loop two times to display the first posts, reset it and then start it again after your widget - skipping the two first posts.

    You may achieve this like so:

    First run the loop, displaying the two first posts.

    // The Query
    $the_query = new WP_Query( array( 'posts_per_page' => 2 ) );
    // The Loop
    if ( $the_query->have_posts() ) {
        //Display post
    }
    

    Reset the query, and display your widget

    /* Restore original Post Data */
    wp_reset_postdata();
    
    //Your widget here.
    

    Display the next posts, skipping the first two.

    // The Second Query
    $the_query = new WP_Query( array( 'posts_per_page' => 10, 'offset' => 2  ) );
    // The Loop
    if ( $the_query->have_posts() ) {
        //Display post
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录