【问题标题】:Inject ads in WordPress archive在 WordPress 存档中注入广告
【发布时间】:2017-12-17 21:03:36
【问题描述】:

下面的代码用于在 wordpress 存档页面上的第 5 篇文章之后注入广告横幅,我想在第 1 篇和第 5 篇文章之后注入横幅,但我不知道如何修改代码来满足我的需要为。

<?php
function insert_between_posts( $post ) {
    global $wp_query;

    // Check if we're in the main loop
    if ( $wp_query->post != $post )
        return;

    // Check if we're at the right position
    if ( 5 != $wp_query->current_post )
        return;

    // Display the banner
    echo '
    <div banner>BANNER</div>
    ';
    }
   add_action( 'the_post', 'insert_between_posts' );
   ?>

【问题讨论】:

    标签: php wordpress adsense


    【解决方案1】:

    你有没有尝试改变

    if ( 5 != $wp_query->current_post )
    

    if ( 5 % $wp_query->current_post == 0 || 1 != $wp_query->current_post)
    

    每当“current_post”是 5 的倍数或等于 1 时,我的代码都会显示横幅

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-15
      • 2015-07-16
      • 1970-01-01
      • 2013-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多