如何在返回函数中添加此HTML PHP代码?

时间:2015-01-21 09:24:14

标签: php function

我想在WordPress的摘录中显示以下HTML代码。在原始代码WordPress中使用

return '...';

我想在返回时添加以下PHP和HTML代码:

 <div class="share-icons-r">
     <div class="share-r">
      <h3>Share</h3>
     </div>

     <div class="icons-r">
      <a target="_blank" href="http://www.facebook.com/share.php?u=<?php echo get_permalink();?>&title=<?php the_title(); ?>">
      <img src="http://www.mywebsite.com/fb.png" />
      </a>
     </div>
 </div>

也许以下是该功能的完整代码

if ( ! function_exists( 'x_excerpt_string' ) ) :
function x_excerpt_string( $more ) 
{ 
$stack = x_get_stack();
   if ( $stack == 'integrity' ) 
      {
   return ' ... <div><a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>

</div>';} 


else if ( $stack == 'renew' )
  {
  return ' ... <a href="' . get_permalink() . '" class="more-link">' . __( 'Read More', '__x__' ) . '</a>';} 

else if ( $stack == 'icon' ) 
  {
  return ' ...';
  } 

  else if ( $stack == 'ethos' ) 
  {
  return '...';
  }
}
add_filter( 'excerpt_more', 'x_excerpt_string' );
endif;

1 个答案:

答案 0 :(得分:1)

将您的html放在.php文件中。然后写这个

ob_start();
include 'my_htlm.php';
$out = ob_get_contents();
ob_end_clean();

然后退出$。 这将包括你在$ out var中的html,当你通过ajax或任何方法返回它时,你只需将它注入你的页面。