doufei1852 2014-09-17 19:20
浏览 64

WordPress的。 在灯箱插件中显示短代码

I am working on a WordPress theme. I use a plugin to display pictures on a page (for each post 1 picture), Whenever one of this pictures is clicked the following code registers this and opens a lightbox with the content of the post in it:

<?php
if($_REQUEST['popup']!=''){

$postObj = get_post( $_REQUEST['pid'] );


echo '<div class="ostContent">'.$postObj->post_content.'</div>';

exit;
?>

This all works fine.

Now the problem is that all content get displayed nicely. but for some reason shortcodes don't work. and also when I use a widget in post plugin to display a widget in the post, it doesn't get displayed.

First I tought I needed to enable shortcodes. So I changed this:

echo '<div class="ostContent">'.$postObj->post_content.'</div>';

with this:

echo '<div class="ostContent">'.do_shortcode( $postObj->post_content ).'</div>';

But still nothing. So now I have no idea what to change to make the lightbox show widgets Hope anyone knows the solution!

EDIT: when I open the post outside the lightbox (by just going to the single page) the shortcode get used like it should be. so somehow the code above don't recognize the shortcode or...

  • 写回答

2条回答 默认 最新

  • dongqin1075 2014-09-17 19:51
    关注

    According to a sample here: http://codex.wordpress.org/Function_Reference/do_shortcode

    It looks like you need to change: echo '<div class="ostContent">'.do_shortcode( $postObj->post_content ).'</div>';

    to:

    echo '<div class="ostContent">'.do_shortcode([shortcode_in_brackets]).'</div>';
    

    This should actually display the code. I am assuming that you have defined the actual text in the widget in which the shortcode applies.

    Otherwise in the way you currently do it the PHP fires before the post_content even has a value.

    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改