我使用wordpress作为我们公司网站的CMS。我们大约有5-10页,我们希望在其中插入相同的行动内容的呼吁。
如何创建允许我将帖子中的内容嵌入到页面中的短代码?
谢谢史蒂文。
发布于 2013-01-15 11:37:19
我还没有对此进行测试,但您可能会想要一些类似以下内容的东西:
function create_call_to_action_shortcode( $atts ) {
$call_to_action_content = '';
$query = new WP_Query( array( 'p' => $post_id, 'no_found_rows' => true ) );
if( $query->have_posts() ) {
$query->the_post();
remove_filter( 'the_content', 'sharing_display', 19);
$call_to_action_content = apply_filters( 'the_content', get_the_content() );
add_filter( 'the_content', 'sharing_display', 19);
wp_reset_postdata();
}
return $call_to_action_content;
}
add_shortcode( 'call_to_action', 'create_call_to_action_shortcode' );`
在页面(或其他帖子)中,只需在页面/帖子内容中插入[call_to_action]
即可。
你可以在短码here上找到更多信息。:)
编辑:
为了从帖子内容中移除共享按钮,您需要调用remove_filter( 'the_content', 'sharing_display', 19);
。我已经更新了上面的代码。
https://stackoverflow.com/questions/14330504
复制相似问题