为我的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