• I’m using a lightbox plugin thats only being used on certain pages of the blog, but it loads on every page. How can I make it load only on those certain pages?

    Pls help,
    Thanks,
    Ajay

Viewing 6 replies - 1 through 6 (of 6 total)
  • <?php if (is_page(array(42,'about-me','About Me And Joe'))) { ?>
    lighbox stuff here
    <? } else { ?>
    
    <? } ?>

    Change the 42,’about-me’,’About Me And Joe’ to either the IDs of your pages, or the slugs of your pages.

    Thread Starter ajaytct

    (@ajaytct)

    Thanks jessn! Where exactly should I put this code? Which file does the ‘lightbox stuff here’ code appear in after I install it?

    There’s a ‘jquery-lightbox.php’ file that appears when I click on ‘edit’ under the plugin name. Should I put your code in that?

    Ahhhh…you’re using a plugin. I don’t know if you can do that then because I think the plugin inserts that code into the header, and you wouldn’t be able to use the above code. But perhaps there’s a way to modify that file. Maybe someone else will have an answer for that.

    Your other option would be to upload the js files manually, and then use the above code in your header.php file, between the <head> and </head>
    It would look something like:

    <?php if (is_page(array(42,'about-me','About Me And Joe'))) { ?>
    <script src="<?php bloginfo('template_url'); ?>/js/jquery.js" type="text/javascript"></script>
    <? } else { ?>
    
    <? } ?>
    Thread Starter ajaytct

    (@ajaytct)

    Where would i upload the js files to? Also, the plugin folder comes with a ‘css’ and an ‘images’ folder. Do I upload them into the same place as well?

    The plugin I’m using – http://wordpress.org/extend/plugins/jquery-lightbox-balupton-edition/

    Thanks again for your help. This plugin is heavy and its taking up an extra 100KB of bandwidth everytime a page loads.

    You can download it from here: http://leandrovieira.com/projects/jquery/lightbox/

    You’ll need to put the css file in your CSS folder, and upload the js folder. Both to your theme. Then in your head add something like

    <?php if (is_page(array(42,'about-me','About Me And Joe'))) { ?>
    
    <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.js"></script>
        <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/jquery.lightbox-0.5.js"></script>
    
       <link rel="stylesheet" type="text/css" href="<?php bloginfo('template_url'); ?>/css/jquery.lightbox-0.5.css" media="screen" />
     <script type="text/javascript">
        $(function() {
            $('#gallery a').lightBox();
        });
        </script>
    
    <? } else { ?>
    
    <? } ?>

    What images are you going to add a lighbox effect to? Will it only be a couple here or there or all images in your loop?

    emily1

    (@emily1)

    If you only want it to run in the content on single posts, is there a way to turn it off for everywhere else?

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How do I load javascript only on specific pages?’ is closed to new replies.