2017-12-17 21 views
0

以下のコードは、Wordpressアーカイブページの5番目の投稿の後に広告バナーを挿入するために使用されています.1番目と5番目の投稿の後にバナーを挿入したいのですが、私はそれが必要なもののために。WordPressアーカイブに広告を挿入する

<?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'); 
    ?> 

答えて

0

あなたは私のコードは毎回バナーを表示していました "current_post" は5の倍数である、または1

に等しい

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

if (5 != $wp_query->current_post) 

を変更しようとしました

関連する問題