0

I think I just coded myself into a corner. I am setting up a page with an image. The image is an imagemap with lots of links. When you click on the link, it opens a post in a colorbox. So far I have managed to get this part working using a combination of the Lightbox Plus and Post Template plugins.

Unfortunately this involves assigning each post to a specific template. The template simply removes the title/image/menu. But this permanently alters the post display. I need to post to still show the full header if it is accessed through the normal menu or from a Google search.

How can I display a post differently based on how it is accessed? OR - how can I insert just the post content into the colorbox window without using a custom page or post template?

2
  • Can you please add relevant code to your question.
    – s_ha_dum
    Commented Mar 18, 2013 at 19:48
  • I really don't have any yet. I'm using two plugins, and the two pages I added are kinda what I'm trying to avoid altogether.
    – dixonge
    Commented Mar 18, 2013 at 21:25

1 Answer 1

2

A potential solution would be to first get rid of the Post Template plugin and just use the default single.php to render single post views.

Then add a get variable onto the end of your imagemap links, so they're something like domain.com/post-name/?view=lightbox

Then filter the single_template to load your lightbox view template when the GET var is detected:

function wpa_lightbox_single( $template ){
    if( isset( $_GET['view'] ) )
        $template = locate_template( 'lightbox-view.php' );

    return $template;
}
add_filter( 'single_template', 'wpa_lightbox_single' );
8
  • oh man - I'm going to have to brush up on my PHP aren't I? sigh
    – dixonge
    Commented Mar 18, 2013 at 21:16
  • Rats - tried to edit and went over the 5 minute restriction. Meant to add: "Oh well, it was inevitable. But seriously, Milo - thank you. This looks promising. The Lightbox Plus Colorbox plugin requires adding a class variable to the link. Would this potentially bypass that? Also, would this function be something that I added directly to single.php?"
    – dixonge
    Commented Mar 18, 2013 at 21:23
  • So I added the function code into functions.php and this didn't seem to work. Should the code go into single.php instead?
    – dixonge
    Commented Mar 18, 2013 at 21:40
  • the function goes in functions.php. your links will still need the lightbox class added as well as the appended view GET variable. You can test if it's working on its own by viewing a single post, then adding ?view=lightbox directly to the URL in your browser. You'll also need to change lightbox-view.php to the name of the template you want to load in the lightbox.
    – Milo
    Commented Mar 18, 2013 at 21:55
  • I kept your code as is - added it to functions.php - renamed my content-only page template to lightbox-view.php - disabled the Post Template plugin. Unfortunately it seems to be using single.php with or without the 'view' variable. Here is the link to the test page - all three links have the class variable for the lightbox plugin. staging.vagabondians.com/sample-page
    – dixonge
    Commented Mar 18, 2013 at 23:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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