logo
Ask your WordPress questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$8
Slider into template file

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/

This question has been answered.

Magas ramo | 06/07/11 at 7:23am Edit

Previous versions of this question: 06/07/11 at 7:53am | 06/07/11 at 7:53am | 06/07/11 at 8:02am | 06/07/11 at 8:25am | 06/07/11 at 9:37am | 06/07/11 at 9:38am | 06/07/11 at 9:43am

(6) Possible Answers Submitted...

See a chronological view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    06/07/11
    7:27am
    Peter Michael says:

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

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

    • 06/07/11 9:41am

      Peter Michael says:

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

    • 06/07/11 9:50am

      Magas ramo says:

      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

    • 06/07/11 10:07am

      Peter Michael says:

      A 'colon'

      :

      A 'semi colon'
      ;

      Pay more attention to detail please.

    • 06/07/11 10:19am

      Magas ramo says:

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

    • 06/07/11 10:23am

      Peter Michael says:

      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.

  • avatar
    Last edited:
    06/07/11
    7:28am
    Michael Fields says:

    Try using a colon here:

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


    You currently have a semi colon ...

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

    • 06/07/11 8:27am

      Michael Fields says:

      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 ) : ?>

    • 06/07/11 10:24am

      Magas ramo says:

      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

    • 06/07/11 10:36am

      Michael Fields says:

      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.

  • avatar
    Last edited:
    06/07/11
    7:44am
    Baki Goxhaj says:

    Use a colon in stead of the semicolon here:

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


    • 06/07/11 7:56am

      Baki Goxhaj says:

      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.

    • 06/07/11 8:09am

      Baki Goxhaj says:

      You are feeding no data to the foreach loop.

  • avatar
    Last edited:
    06/07/11
    7:52am
    Jerson Baguio says:

    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>

  • avatar
    Last edited:
    06/07/11
    8:00am
    Denzel Chia says:

    Hi,


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


    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

    Previous versions of this answer: 06/07/11 at 8:00am

  • avatar
    Last edited:
    06/07/11
    8:01am
    Jimish Gamit says:

    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";
    } ?>

    Previous versions of this answer: 06/07/11 at 8:01am

    • 06/07/11 8:02am

      Jimish Gamit says:

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

This question has expired.



Denzel Chia, Julian Lannigan voted on this question.



Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.