douxianxing5712 2013-10-14 14:28
浏览 35
已采纳

摘录中的php wordpress短代码

I am looking for away to use shortcodes in post excerpts that will be called via:

 $post_object->post_excerpt;

I have the function set up to pull the excerpts but I am struggling to pull the shortcode. at the moment it just returns a string EG: "[short]foo[/short]". Does anyone know what I need to add to functions.php to allow shortcode usage in this way? WP 3.6

EDIT: Also the call to the excerpt is nested inside an already existing shortcode function, which works fine.

Edit 2:

To clarify, I am using 2 function. One to create a format for the page "box":

//create box shortcode
function box( $atts, $content = null) {
    $p_id = $atts['post'];
    $p = get_post($p_id);
    $output = '<div class="box"><a href="'.get_permalink($p_id).'"><div class="box_inner"><h1>'.$p->post_title.'</h1><p>'.$p->post_excerpt.'</p></div></a></div>';
    return $output; 
} 
add_shortcode("box", "box");

And one to create an icon "char" (this is the function I want to use on the excerpt in the short code above):

//big text for icons shortcode
function icon( $atts, $content = null) {
 return '<p style="text-align: center; font-size: 100px;>'.$content.'</p>';
}
 add_shortcode("icon", "icon"); 

I may be way off base here, is it even possible to use shortcodes in this fashion? and if so how do I stop the excerpt from ignoring the shortcode format?

  • 写回答

4条回答 默认 最新

  • dongzhang5787 2013-10-14 15:35
    关注

    For anyone who is looking.

    I made a school boy error here. I had the filter:

    add_filter( 'post_excerpt', 'do_shortcode');
    

    But forgot to use:

    apply_filters('post_excerpt', $p->post_excerpt);
    

    Now works fine :-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应