Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Slider into template file WordPress

  • SOLVED

Hi there,



TEMPLATE SLIDER WORK PERFECTLY :

<?php

/*
Template Name: Slider
*/

get_header(); ?>

<div id="container">
<div id="content" role="main">

<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<?php if ( is_front_page() ) { ?>
<h2 class="entry-title"><?php the_title(); ?></h2>
<?php } else { ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<?php } ?>

<div class="entry-content">
<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>

<div id="slider">
<?php foreach($slides as $num => $slide) : ?>

<?php if($slide['link'] != '') echo '<a href="' . $slide['link'] . '">'; ?>
<img src="<?php echo $slide['src'] ?>" alt="" title="<?php echo $slide['caption']; ?>">
<?php if($slide['link'] != '') echo '</a>'; ?>

<?php endforeach; ?>
</div>

</div><!-- .entry-content -->
</div><!-- #post-## -->

<?php comments_template( '', true ); ?>

<?php endwhile; ?>

</div><!-- #content -->
</div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>




template slider demo : http://thesispro.ramoservice.com/slider-template/
....................................................................................................

But i want to integrate slider into template file and I'm not sure how can i do this ?
maybe


<script type="text/javascript">
$(window).load(function() {
$('#slider').nivoSlider();
});
</script>

<div id="slider">
<?php foreach($slides as $num => $slide) : ?>

<?php if($slide['link'] != '') echo '<a href="' . $slide['link'] . '">'; ?>
<img src="<?php echo $slide['src'] ?>" alt="" title="<?php echo $slide['caption']; ?>">
<?php if($slide['link'] != '') echo '</a>'; ?>

<?php endforeach; ?>
</div>



error message :
Warning: Invalid argument supplied for foreach() in /var/www/vhosts/ramoservice.com/subdomains/thesispro/httpdocs/wp-content/themes/thesis_181/slidera.php on line 9

LINK :http://thesispro.ramoservice.com/

Answers (6)

2011-06-07

Peter Michael answers:

<?php foreach($slides as $num => $slide) ;?>
should be
<?php foreach($slides as $num => $slide) :?>


Peter Michael comments:

Your original question has been answered correctly by some users. Please post the new error / slider integration as a new question.


Magas ramo comments:

If question answered why slider doesnt work , is not new question but biggers description on first question .

take o look on code is exactly the same


<?php foreach($slides as $num => $slide) ;?>
and
<?php foreach($slides as $num => $slide) :?>

display exactly the same error message


Peter Michael comments:

A 'colon'
:
A 'semi colon'
;
Pay more attention to detail please.


Magas ramo comments:

I have tried both colon and semi colon , but again the same error


Peter Michael comments:

Your first question was 'Slider not loading (syntax error) ' and the error was
syntax error, unexpected T_ENDFOREACH on line 7
This question has been answered and the error fixed by replacing the semi colon with a colon.

2011-06-07

Michael Fields answers:

Try using a colon here:

<?php foreach($slides as $num => $slide) : ?>

You currently have a semi colon ...

<?php foreach($slides as $num => $slide) ; ?>


Michael Fields comments:

Oh, Ok...

The easiest way to deal with this is to cast $slides as an array before iterating over it:

<?php foreach( (array) $slides as $num => $slide ) : ?>


Magas ramo comments:

thank you for you answers Michael i really appreciate it

<?php foreach( (array) $slides as $num => $slide ) : ?>

this code remove the error message but does not show slider



<?php foreach($slides as $num => $slide) ; ?>


<?php foreach($slides as $num => $slide) : ?>



both colon and semi colon , but again the same error


thanks


Michael Fields comments:

Basically, you're going to have to find the place in the theme where the $slides variable is being set and make the same functionality work in your new template. Unfortunately, there is no way to determine where this happens by the code you supplied.

2011-06-07

Baki Goxhaj answers:

Use a colon in stead of the semicolon here:

<?php foreach($slides as $num => $slide) <strong>:</strong> ?>


Baki Goxhaj comments:

I need to see the code that $slides refers too. $slides needs to be an array. Can you show it to us. The error is saying that $slides is not an array or is not set altogether.


Baki Goxhaj comments:

You are feeding no data to the foreach loop.

2011-06-07

Jerson Baguio answers:

Try this changes :

<?php foreach($slides as $num => $slide):?>



<?php if($slide['link'] != '') echo '<a href="' . $slide['link'] . '">'; ?>

<img src="<?php echo $slide['src'] ?>" alt="" title="<?php echo $slide['caption']; ?>">

<?php if($slide['link'] != '') echo ''; ?>

<?php endforeach; ?>

</div>

2011-06-07

Denzel Chia answers:

Hi,

<blockquote>
Invalid argument supplied for foreach() in /var/www/vhosts/ramoservice.com/subdomains/thesispro/httpdocs/wp-content/themes/thesis_181/slider.php on line 2
</blockquote>

This means your $slides variable is not an array or empty array.
What supplies your $slides variable? Just make sure it is an valid array.

Thanks.
Denzel

2011-06-07

Jimish Gamit answers:

Invalid argument supplied for foreach() can happen if you try to do a foreach on an variable that isn't an array. Maybe it is "supposed to" be an array


<?php if(is_array($slides)){ ?>
<?php foreach($slides as $num => $slide):?>
<?php if($slide['link'] != '') echo '<a href="' . $slide['link'] . '">'; ?>
<img src="<?php echo $slide['src'] ?>" alt="" title="<?php echo $slide['caption']; ?>">
<?php if($slide['link'] != '') echo ''; ?>
<?php endforeach; ?>
<?php }else{
echo "NO DATA";
} ?>


Jimish Gamit comments:

try to print $slides just before to FOREACH... I am sure its not getting any data