爲我的WordPress的網站創建一個自定義函數,將在帖子內容下面添加一個評論部分,我需要從另一個文件插入這個函數到我添加到我的functions.php的自定義函數中。我需要從不同的文件得到這段代碼$buffy .= $this->get_review();
在此功能工作:如何從另一個php文件插入php代碼?
function content_injector($content) {
global $wp_query;
$postid = $wp_query->post->ID;
if (is_single((get_post_meta($postid, 'top_ad', true) != 'off'))) {
$top_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single((get_post_meta($postid, 'bottom_ad', true) != 'off'))) {
$bottom_ad = do_shortcode('[td_ad_box spot_name="Ad spot -- topad"]');
}
if (is_single()) {
$review = //HOW DO I ADD THAT get_review CODE HERE?
$custom_share = '<div id="title-deel"><h4 class="block-title"><span>DEEL</span></h4></div>' . do_shortcode('[ssba]');
$facebook_comments = '<div id="title-reageer"><h4 class="block-title"><span>REAGEER</span></h4></div>' . '<div class="fb-comments" data-href="' . get_permalink() . '" data-colorscheme="light" data-numposts="5" data-mobile="false" data-width="700"></div>';
}
$content = $top_ad . $content . $bottom_ad . $custom_share . $facebook_comments;
return $content;
}
add_filter('the_content', 'content_injector');
正如你可以看到我需要的get_review功能添加到$review
,但我不能讓我自己的工作。如何使這項工作?
你有沒有考慮[包括()](http://www.php.net/manual/en/function.include.php)? –
是無法獲得get_review函數的包含功能! – Rik
你應該把所有的函數放在'functions.php'文件中,以便在WordPress上工作。但是,'include'還是'require'應該可以完成這項工作? – Maaz