Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing a plugin which requires to open a single wordpress post inside of a lightbox. Here are a few details :

  • Currently,I am using colorbox for lightbox. The lightbox is triggered to open an external .php file which received the post id as $GET variable.
  • Only the Title, Meta information, Content and comments part should open in the lightbox and not the theme header and footers.
  • All the shortcodes , embedded youtube links etc should work in the opened post.
  • It would be great if there is a way to pick up the current theme's single.php file, strip the header , sidebar and footer from it and display only the formatted content. But i believe that depends on themes and is not a generic solution

Here is the current plugin link :http://test.anshulsharma.in/

The current code for the external php file is :

if(!function_exists('get_post'))
{
require_once("../../../../wp-load.php");
}
$thepost = get_post($_GET["ID"]);
$thecontent = $thepost->post_content;
$thetitle = $thepost->post_title;
$thelink = get_permalink($_GET["ID"]);
?>
    <div id="cg-post-container" style="width:<?php echo get_cg_option('lightbox_width'); ?>px;">
    <div id="cg-post-title">
    <a href="<?php echo $thelink; ?>"><?php echo $thetitle; ?></a>
    </div>
    <div id="cg-post-content">  
            <?php echo $thecontent; ?>
    </div>          
</div>

In the current version of the plugin, only the posts content shows up. Shortcodes dont work and embeded links dont show up. Also there is no way to view or add comments. I am willing to write a custom single.php file for this and add my own styling . But i just want to know the BEST way to do it and also how to communicate the post id (from the $GET variable to the single.php) to the lightbox.

share|improve this question
    
What do you mean "custom links don't show up"? What are custom links? As far as the shortcodes are concerned, you need to run the post content through the content filters so that everything that's supposed to happen to the content does. Try replacing <?php echo $thecontent; ?> with <?php echo apply_filters('the_content', $thecontent); ?> –  guiniveretoo Nov 16 '12 at 15:05
    
Nevermind the custom links. I meant embeded youtube videos which work fine. And shortcodes are now being processed properly per your comment. Also, i want to include the wp_head event hook in the .php file (So that plugins that add some content in the head section can work) but this causes jquery to load twice (once on main page and once in the lightbox). This causes the lightbox to stop working. –  Anshul Nov 16 '12 at 18:59
add comment

1 Answer

You should consider using the AJAX API. Once you get the hang of it, it is easier and saves you a lot of headache.

You question specifically: Your Lightbox should produce identifiable markup that you can use to hide the elements you don't want, much like you'd create a printer friendly page. I don't specifically know about LightBox, but ThickBox creates several <div>s with the TB_ prefix on the ids, one of which is TB_ajaxContent so...

#TB_ajaxContent .header { display:none }

... will hide the header with class header. Fairly simple, really.

For your other issues, just load the single post page in LightBox and hide the parts you don't want. Everything should work like normal. You probably don't even need that callback script, honestly. You can just load the URL of the page you want.

share|improve this answer
    
thanks. Your solution looks interesting, but when I pass the post permalink as the url for colorbox. It does not do anything. It needs a file url (.html or .php) to load the post into the lightbox –  Anshul Nov 16 '12 at 15:01
    
That is surprising. Can you tell me exactly which 'lightbox' you are using? There are several scripts using 'lightbox' in their names. Worst case, you can use the AJAX API and load the page that way. –  s_ha_dum Nov 16 '12 at 15:06
    
I am using "Colorbox" jacklmoore.com/colorbox –  Anshul Nov 16 '12 at 15:23
    
The "Outside Webpage" example seems to do what you say Colorbox does not support. –  s_ha_dum Nov 16 '12 at 15:35
    
I cannot modify CSS of html inside an iframe. Not without using JS atleast See this. also resizing the frame becomes more complex since the height is to be adjusted according to the content –  Anshul Nov 16 '12 at 18:40
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.