我正在集成两个wordpress插件。我想做的是将这段代码<?php DisplayStars(get_the_ID()); ?>
添加到另一个插件的函数中。我尝试了$html = '<?php DisplayStars(get_the_ID()); ?>';
,但php显示错误。谢谢你的帮助。
function wpbusdirman_post_excerpt($count)
{
$wpbusdirman_gpid=wpbusdirman_gpid();
$wpbusdirman_permalink=get_permalink($wpbusdirman_gpid);
$html = '';
$html .= '<div id="wpbdmlistings"';
$isasticky = get_post_meta(get_the_ID(),'sticky');
if(isset($isasticky) && !empty($isasticky))
{
$isasticky=$isasticky[0];
}
if(isset($isasticky) && ($isasticky == 'approved'))
{
if($count&1)
{
$html .= ' class="wpbdmoddsticky"';
}
else
{
$html .= ' class="wpbdmevensticky"';
}
}
else
{
if($count&1)
{
$html .= ' class="wpbdmodd"';
}
else
{
$html .= ' class="wpbdmeven"';
}
}
$html .='><div class="listingthumbnail">' . wpbusdirman_display_the_thumbnail() . '</div><div class="listingdetails">';
$html .= wpbusdirman_display_the_listing_fields();
$html .= wpbusdirman_view_edit_delete_listing_button();
$html .= '</div><div style="clear:both;"></div></div>';
return $html;
}
您正在使用的代码库是php。您添加的代码是php。这意味着,您不需要将其添加到html中,只需调用函数即可。(如果函数不在此文件中,则可能需要在文件顶部包含一个include才能使其工作)
$html .= DisplayStars(get_the_ID());
应该是在调用中将文本添加到html中所需的全部内容。
当你做这样的事情时:
<?php return "<?php echo('foo'); ?>"; ?>
然后PHP不知道(或不关心)引号之间的内容——据它所知,它只是文本。但是,您可以让PHP使用eval
:来解释字符串
<?php
$command = "echo('foo');";
eval($command);
?>
这将导致PHP打印出"foo"。但是要注意,eval
是危险的——请参阅PHP手册中的注释。