您的代码有几个问题:
如果要输出纯HTML,必须关闭PHP上下文:function foo(){ ?><strong><?php }
不要重复你自己的话。始终在变量或函数中存储重复值。写<a href
不止一次是一个bug请勿使用get_the_title()
在属性中。使用the_title_attribute( array ( \'echo\' => FALSE ) )
相反,您也可以在HTML输出中获得意外的标记请勿使用bloginfo(\'stylesheet_directory\')
. 使用get_stylesheet_directory_uri()
在里面child themes only 和get_template_directory_uri()
在所有其他情况下请勿双重转义&
.https://delicious.com/post?. 多年来一直如此生成的代码可能如下所示:
function pietergoosen_sosiale_netwerk_deel_knoppies()
{
$services = array (
\'facebook\' => array (
\'url\' => \'http://www.facebook.com/sharer.php?u=%1$s&t=%2$s\',
\'text\' => \'Share on Facebook.\'
),
\'twitter\' => array (
\'url\' => \'http://twitter.com/home/?status=%1$s%%20-%%20%2$s\',
\'text\' => \'Tweet this!\'
),
\'google\' => array (
\'url\' => \'http://www.google.com/bookmarks/mark?op=edit&bkmk=%2$s&t=%2$s\',
\'text\' => \'Google+1.\'
),
\'stumbleupon\' => array (
\'url\' => \'http://www.stumbleupon.com/submit?url=%1$s&title=%2$s\',
\'text\' => \'StumbleUpon.\'
),
\'digg\' => array (
\'url\' => \'http://digg.com/submit?phase=2&url=%1$s&title=%2$s\',
\'text\' => \'Digg this!\'
),
\'delicious\' => array (
\'url\' => \'https://delicious.com/post?url=%1$s&title=%2$s\',
\'text\' => \'Bookmark on Delicious.\'
),
\'gmail\' => array (
\'url\' => \'https://mail.google.com/mail/?view=cm&fs=1&to&su=%1$s&t=%2$s\',
\'text\' => \'Share per Gmail.\'
)
);
$img_base = get_template_directory_uri() . \'/images/%s.png\';
$title = the_title_attribute( array ( \'echo\' => FALSE ) );
$url = urlencode( get_permalink() );
print \'<h4>Deel die pos met ander</h4>\';
foreach ( $services as $name => $service )
{
$href = sprintf( $service[\'url\'], $url, urlencode( $title ) );
$src = sprintf( $img_base, $name );
printf(
\'<a href="%1$s" title="%2$s"><img src="%3$s" alt="%2$s" /></a>\',
$href,
esc_attr( $service[\'text\'] ),
$src
);
}
}
现在可以在模板中调用此函数:
pietergoosen_sosiale_netwerk_deel_knoppies();