Wordpress Themes - WP Forum at BFA

Wordpress Themes - WP Forum at BFA (http://forum.bytesforall.com/index.php)
-   Atahualpa 3 Wordpress theme (http://forum.bytesforall.com/forumdisplay.php?f=2)
-   -   [SOLVED] page template jquery slideshow (http://forum.bytesforall.com/showthread.php?t=19973)

sstudebaker Mar 23, 2013 02:06 PM

[SOLVED] page template jquery slideshow
 
I'm trying to do add this to a template file and not use a plugin. Using all latest versions - Wordpress ATA 3.711 and WP 3.5.1. I'm pretty new to WP programming so may be going about this all wrong. I'm attempting to read in files from an image folder for a slideshow. Gets hung up after
HTML Code:

<div id="myslides">
.
HTML Code:

<a href="http://74.115.229.75/kids-camp/">Here's the page</a>
. I have added
PHP Code:

<?php wp_enqueue_script("jquery"); ?>

to header.php just before
PHP Code:

<?php wp_head(); ?>

. Maybe I'm not allowed to call the jquery function or scripts from within the template and if not where do I put them? Trying to modify theme files as little as possible. All tips are welcome as I am learning. Here's the latest version of my code (code is all tested and works outside of WP):
Code:

<?php 
/* Template Name: Custom Interior Page */ 
list($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']) = bfa_get_options();
get_header();
extract($bfa_ata);
global $bfa_ata_postcount;
?>
<script type="text/javascript">
var $j = jQuery.noConflict();

$j($(document).ready(function(){
        $j($('#myslides').cycle({
                fit: 1, pause: 1, timeout: 4000
        }));
}));
</script>
<style> #myslides { height:400px; width:600px; } </style>
<div id="interior_wrapper">
<?php
 
    global $post;
    $post_slug=$post->post_name;

        $img_directory = '../../images/'.$post_slug;
        // echo $directory;                 
        // Styling for images       
        echo '<div id="myslides">';       
        foreach ( new DirectoryIterator($img_directory) as $item ) {                       
                if ($item->isFile()) {
                        $path = $img_directory . '/' . $item;       
                        echo '<img src="' . $path . '"/>';       
                }
        }       
        echo '</div>';
?>       
       
</div>
<script src="../../scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="../../scripts/jquery.cycle.lite.js" type="text/javascript"></script>
<?php get_footer(); ?>


juggledad Mar 23, 2013 02:23 PM

Why don't you want to use a plugin? Most are built to intergrate easily, you won't have to maintain it yourself.

What do you mean that it gets hung up?
depending on your host the '../../' may be violating a security rule, try using the full url

sstudebaker Mar 23, 2013 02:55 PM

If you view source on page it doesn't get any further than the div for the slideshow. I have code that works (outside of WP) so would rather just keep it simple and not use a plugin that may or may not do what I want. I have some other complicated plugins to add in later so using as few as I can so as not to bog down the system.

Used full URL for scripts and still nothing. Seems to be broken at

Code:

foreach ( new DirectoryIterator($img_directory) as $item ) {                       
                if ($item->isFile()) {
                        $path = $img_directory . '/' . $item;       
                        echo '<img src="' . $path . '"/>';       
                }
        }

Latest template version

Code:

<?php 
/* Template Name: Custom Interior Page */ 
list($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']) = bfa_get_options();
get_header();
extract($bfa_ata);
global $bfa_ata_postcount;
?>

<script type="text/javascript">
var $j = jQuery.noConflict();

$j($(document).ready(function(){
        $j($('#myslides').cycle({
                fit: 1, pause: 1, timeout: 4000
        }));
}));
</script>
<style> #myslides { height:400px; width:600px; } </style>
<div id="interior_wrapper">
<?php
 
    global $post;
    $post_slug=$post->post_name;

        $img_directory = '../../images/'.$post_slug;
        // echo $directory;                 
        // Styling for images       
        echo '<div id="myslides">';       
        foreach ( new DirectoryIterator($img_directory) as $item ) {                       
                if ($item->isFile()) {
                        $path = $img_directory . '/' . $item;       
                        echo '<img src="' . $path . '"/>';       
                }
        }       
        echo '</div>';
?>       
       
</div>
<script src="http://74.115.229.75/scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="http://74.115.229.75/scripts/jquery.cycle.lite.js" type="text/javascript"></script> 
<?php get_footer(); ?>


sstudebaker Mar 23, 2013 04:53 PM

I have part of problem narrowed down to issue with opendir and path to images folder. Could you take a quick look and let me know why folder is wrong. I've asked wordpress forum but no response from anyone. I can see image at http://74.115.229.75/wp-content/them...amp/KCimg1.jpg but script tells me - There is an error with your image directory! Page is at http://74.115.229.75/kids-camp/ and here is php code:
Code:

<?php
 
    global $post;
    $post_slug=$post->post_name;

        $img_directory = bloginfo("template_directory");
        $img_directory .= '/images/'.$post_slug;
        echo $img_directory;                 
        // Styling for images       
        echo '<div id="myslides">';
        if ($handle = @opendir($img_directory) or die("There is an error with your image directory!")) {
                while (false !== ($file = readdir($handle))) {
                    if (strpos($file, ".jpg")) {
                                $path = $img_directory . '/' . $file;       
                                echo '<img src="' . $path . '"/>';       
                    }
                }
                closedir($handle);
        }
        echo '</div>';
?>


juggledad Mar 23, 2013 08:13 PM

Do a google search on 'wordpress bloginfo' and see what it returns

sstudebaker Mar 23, 2013 10:09 PM

Hmmm I can see exactly what it returns as I have an echo on the variable. If you look at the page you can see what I get back which seems right but its not working. Sorry I don't get the sense you are looking at my problem/

juggledad Mar 24, 2013 04:00 AM

Quote:

Sorry I don't get the sense you are looking at my problem
that was a two minute look whale I was out at dinner

What is the file permission for the folder?

sstudebaker Mar 24, 2013 09:52 AM

Thanks for yur help so far! I think I am getting closer. I have loaded following code into header.php before wp_head ();
PHP Code:

<?php wp_enqueue_script("jquery"); ?>
<?php 
if (is_page_template('custom_interior.php'))
    
wp_enqueue_script('jquery-cycle'get_template_directory_uri() . '/js/jquery.cycle.lite.js'); ?>

I added jquery.cycle.lite.js to my theme js folder.
Put styles in proper place.
My template php to load images is working now. I needed server path to get opendir to work right.
I'm still unsure how to handle the actual jquery function. Should I make another js file for this function (with conditional statement added for template) and where do I call / load it?
Here's latest template code and page I'm testing:
Code:

<?php 
/* Template Name: Custom Interior Page */ 
list($bfa_ata, $cols, $left_col, $left_col2, $right_col, $right_col2, $bfa_ata['h_blogtitle'], $bfa_ata['h_posttitle']) = bfa_get_options();
get_header();
extract($bfa_ata);
global $bfa_ata_postcount;
?>

<script type="text/javascript">
jQuery(document).ready(function(){
        $('#myslides').cycle({
                fit: 1, pause: 1, timeout: 4000
        });
});
</script>

<div id="interior_wrapper">
<?php
 
    global $post;
    $post_slug=$post->post_name;

        $img_path .= '/home/galenalodge/www/wp-content/images/'.$post_slug;
        $img_directory = get_bloginfo("template_directory");
        $img_directory .= '/images/'.$post_slug;
        // echo $img_directory;                 
        // Styling for images       
        echo '<div id="myslides">';
        if ($handle = @opendir($img_path) or die("There is an error with your image directory!")) {
                while (false !== ($file = readdir($handle))) {
                    if (strpos($file, ".jpg")) {
                                $path = $img_directory . '/' . $file;       
                                echo '<img src="' . $path . '"/>';       
                    }
                }
                closedir($handle);
        }
        echo '</div>';
?>               
</div>
 
<?php get_footer(); ?>


sstudebaker Mar 24, 2013 11:06 AM

Hey I got it working

juggledad Mar 24, 2013 11:44 AM

congratulations!


All times are GMT -6. The time now is 12:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.