2015-11-15 51 views
0

我們有一個框格,需要把它添加到頂部或內容底部,WordPress的當循環條件完成添加過濾器the_content()

所以我們如何才能在美國這個循環的add_filter(「the_content」裏面,「框DIV');

這是我們的循環

if (is_array($my_box_pos)) { 
     foreach ($my_box_pos as $key => $val) { 
      if ($val[moz]=="bottom" || $val[moz]=="top_and_bottom") 
      sandy_box($bottom); 
     } 
    } 

這是內容過濾

function content_sample($content) { 
    if(is_singular() && is_main_query()) { 
     $new_content = '<p>This is added to the bottom of all post and page content, as well as custom post types.</p>'; 
     $content .= $new_content; 
    } 
    return $content; 
} 
add_filter('the_content', 'content_sample'); 

有人能幫助我嗎?

回答

0
function content_sample($content) { 
    if(is_singular() && is_main_query()) { 
     $new_content = '<p>This is added to the bottom of all post and page content, as well as custom post types.</p>'; 
     if (is_array($my_box_pos)) { 
      foreach ($my_box_pos as $key => $val) { 
       if ($val[moz]=="bottom" || $val[moz]=="top_and_bottom") 
       $content .= $new_content; 
       } 
       else { $content = $new_content . $content; } 
      } 

     } 
     return $content; 
} 
add_filter('the_content', 'content_sample'); 

試試這個,我不確定它是否適合你。

+0

'is_main_query()'在這裏不起作用。 ;-) –