可以使用add_action(loop_start,smtg)
或add_action(loop_end,smtg)
或apply_filters('the_content', $content);
,如:
<?php
$content = apply_filters('the_content', $content);
$content = do_your_stuff;
?>
這真的取決於你想要做什麼...... 看到更多在這裏:http://codex.wordpress.org/Plugin_API/Action_Reference
所有的「上面 - 下面 - 重疊「並不真正相關 - 它們是CSS特定的。 但是,如果你真的想這樣做 - 你可以隨時在con上使用REGEX 10噸...
或另一種方法 - 例如:
function k99_replace_content(){
//get the content
$content= get_the_content(); //get the content as a variable
// where we want to cut ??
// by length ??
$full_length= STRLEN($content);
$cutting_point = ($full_length/ 2);
// regex ??
//do regex stuff here ..
// clip off the first part - if we choose by length
$firstpart = SUBSTR($content, 0, $cutting_point);
// ending '<br>'
$end_point = STRRPOS($firstpart, '<br>');
// add whatever
return SUBSTR($content, 0, $end_point) . "<div>put whatever you want>/div>" . SUBSTR($content, $end_point);
}
的add_filter( 'the_content', 'k99_replace_content');
或最後一個選項,用什麼@IanB這些方法的一個共同建議 - ,包括通過一個過濾器..
我知道這肯定會工作......但我不希望編輯主題文件...對於多場所,我必須爲每個主題安裝執行此操作......這就是爲什麼我試圖開發插件...我想要一個獨立於主題的解決方案... – 2012-03-10 09:28:40