我为我的wordpress网站创建了一个自定义函数,它将在帖子内容下面添加一个评论部分,我需要将这个函数从另一个文件插入到我添加到我的functions.php的自定义函数中。我需要从另一个文件中获取这段代码$buffy .= $this->get_review();
才能使用此函数:
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
,但我不能让它自己运行。如何使这项工作?
答案 0 :(得分:1)
使用include在使用该文件中的任何方法之前包含该文件。
include("file_with_functions.php");
OR
创建一个类(文件名与classname相同)。
包含文件。
创建该类的实例。
通过对象
访问类中的方法