• Resolved tictok

    (@tictok)


    Hi –

    I’ve searched around and found a few people asking previously but no real solutions or answers.

    I’m currently created a site largely using WP as a CMS. One of the pages within the site contains a blog or list of postings.

    What I’d like to achieve is that when a user clicks on a post title or blog link the relevant post content including any pics etc ( the_content() ) is opened in a lightbox style window over the blog / post page instead of taking the reader away to view the single.php page in place of the blog index.

    Does that make sense?

    The closest I’ve managed to get so far is using the iframe functionality of various lightbox plugins and clones, but as is to be expected the iframe shows the header and footer as well which I don’t want.

    I guess I could create an alternative template with a blank header & footer but feel that there must be a much better way to achieve this that just shows the_content() in a lightbox window.

    Any help huuugely appreciated
    cheers
    Stef

Viewing 9 replies - 1 through 9 (of 9 total)
  • I think you have it right, use thickbox with a very simple (only content) template for single.php.

    The other option, which I haven’t tried, but might work, is to create a thickbox template (with only content in it), and somehow pass the post id to it (via GET, perhaps), that way you could load a specific post’s content into it.

    I’m working on something very similar (I just posted my question a few minutes ago).

    Thread Starter tictok

    (@tictok)

    okay – that’s the route I’m going to take for now. Seems the easiest / quickest way to go.

    I have one concern though. I think I’m going to have to create two templates for the single.php –?one that matches the site design and the other being the plain (no header or footer) template for lightbox. I’m a little worried what will happen when someone like google indexes my site. I want the content to be searchable by google but don’t want folk to land on stripped-back pages with no header or footer after following a google search. Need to find a way to only use the bare, striped back single.php template if links from a certain page are followed, otherwise the full template needs to be used.

    I do still think the ‘other’ option (somehow passing post data into lightbox or similar) is a far better way to go, but without a tutorial or someone to give me guidance its a bit out of my reach… when I’ve got time I’ll look into it, but in the meantime if anyone could shed any light and give me any more hints or help I’d be hugely appreciative.

    Many thanks
    Stef

    In my post (https://www.ads-software.com/support/topic/417147) I posted a possible solution to that.

    For regular pages you’d use the single.php, and for the modal, a special template (you’d have to have a page using that template, “lightbox”, in my example).

    When showing the post in the modal, you pass the post id to the simple page.

    Thread Starter tictok

    (@tictok)

    wow – thanks for the quick reply coopersita, taking a look now.
    Will let you know how it goes.

    Cheers
    Stef

    Thread Starter tictok

    (@tictok)

    coopersita, your solution (https://www.ads-software.com/support/topic/417147) worked for me… and I learnt quite a bit in the process whilst I was fiddling around. Many thanks for the help!

    I have one more thing I need to sort out regarding this though.
    It’d probably make more sense to put in a new post as its a different topic (but still related) but thought I’d ask here first.

    So, I now have my original, search friendly, templated pages for each of my ‘product’ posts and also the new much simplified template I now use for pop-up modal ‘product’ posts using Lightbox (or in my case FancyBox), both using the same initial ‘product’ posts.

    I now want to find out if its possible to detect if a browser has Javascript enabled or not so that if it isn’t enabled the user would be given the original permalinks to the fully templated pages instead of the ultra simplified pages intended just for Lightbox (as obviously without JS Lightbox / FancyBox wont work).

    What does anyone think? Possible?

    Cheers
    Stef

    Good point!

    How about in the url you add, via javascript, another GET value for JS enabled. If the variable isn’t set (no JS), then in the lightbox page you redirect to the full size page?

    <h2 class="entry-title"><a href="/lightbox/?pid=<?php echo the_ID(); ?><script type="text/javascrpipt">document.write('&js=yes');</script>"><?php the_title(); ?></a></h2>

    In the lightbox page, before anything else:

    <?php
      if(!isset($_GET['js']){
       $permalink = get_permalink( $_GET['pid'] );
       header( 'Location: '.$permalink ) ;
      }
    ?>

    I think that will probably work, although it may not be very elegant…

    Thread Starter tictok

    (@tictok)

    Hiya –

    Thanks for the suggestion. It might not be very elegant but think it may be a whole lot smoother than the route I took.

    I stuck this in my template and it seems to work okay. The page reload is very obvious though so I think I’ll try your method posted above instead.

    <object><noscript>
    <?
    if ( is_page('example-page')) {
    ?>
    <META HTTP-EQUIV="refresh" CONTENT="0;URL=<?php echo get_option('siteurl'); ?>/?page_id=808">
    <?
    } else { ?>
    // do nothing //
    <? } ?>
    </noscript></object>

    Essentially it checks to see if JS is enabled or not. If its not and the visitor is on a specific page then refresh the browser and load the page set up for non JS users.

    So, which option is best / safest? pros / cons?

    Cheers
    Stef

    Hello,

    I’m looking at doing the same thing and am somewhat confused about how you ended up getting this to work.

    From (https://www.ads-software.com/support/topic/417147), what argument did you pass to the permalink to target the different templates? And did you put that in the archives.php or in the loop? I still don’t have my head wrapped around php yet, so sorry for not understanding.

    Thank you

    FWIW here’s how I did it….
    The edits I made are all in the target template and are very simple
    what it came down to was eliminating the header and footer if it’s loaded in the iframe, for the content to be loaded in an iframe the person MUST have javascript enabled. so if you enclose the header and footer includes inside of noscript tages they don’t fire if it’s in the iframe… also I want to use a little different styling for the div that remains with the content used in the iframe so I place a PHP variable inside of script tags so it only sets the variable IF javascript can run otherwise no extra styling is added to the dive the content is in. hope this helps.

    `
    <noscript>
    <?php get_header(); ?>
    </noscript>
    <script type="text/javascript">
    <?
    $inframe='style="background-color:#FFF; padding:10px; height:460; width:900px;"';
    ?>
    </script>
    <div id="mainContentalt" <?=$inframe?>>
    <?
    if (have_posts()) :
    while (have_posts()) :
    the_post();
    the_content();
    endwhile;
    endif;
    ?>
    <noscript>
    <?php get_footer(); ?>
    </noscript>
    `

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Post content ( the_content() ) in lightbox or modal window?’ is closed to new replies.