我有一個小問題。我已經管理,在某人的幫助下,一個stackoverflow編寫了一個代碼,將動態內容添加到我的所有WordPress的帖子中。代碼現在在我的functions.php文件中,如下所示。替換<?php the_content(); ?>在content-single.php中輸出來自functions.php中的自定義內容代碼
function add_after_post_content($content) {
global $post;
if(!is_feed() && !is_home() && is_singular() && is_main_query()) {
$post_categories = wp_get_post_categories($post->ID);
$cats = array();
foreach($post_categories as $c){
$cat = get_category($c);
$cats[] = array('name' => $cat->name, 'slug' => $cat->slug);
}
$content .= '<strong>'. $post->post_title . '</strong> is a <strong>wallpaper</strong> posted in the ';
foreach($cats as $c){
$content .= $c['name'];
}
$content .= ' category by <strong>Free Wallpapers</strong> on '. $post->post_date . '. <br /><br />';
}
return $content;
}
add_filter('the_content', 'add_after_post_content');
的問題是,我的一些舊的帖子已經在他們的內容,因此無論是舊的內容,以及新的顯示他們腳下。而我希望這是所有帖子的新內容/描述。目前在我的content-single.php中,我認爲這是調用原始發佈內容以及我上面提到的代碼的行。
<?php the_content(); ?>
我想枯萎刪除或修改我的內容的single.php /代碼添加到functions.php文件,以便只有新的代碼顯示動態的描述,並且不顯示原始帖子內容。即如果整個新代碼可以被標記爲content2並且content-single.php代碼將僅輸出這個content2,那麼簡單地將其放置。我試圖只是從functions.php代碼移動代碼
<?php the_content(); ?>
在content-single.php,但這給了我各種各樣的錯誤。
任何有關這個問題的幫助將不勝感激。
最好的問候