0

I have a news ticker in a WordPress theme that I need to to repeat showing post titles after finishing loop (continuous). Currently, after finished showing post titles cycle from the assigned $cat_id it just stop showing nothing.

Here the PHP code:

<?php
                $cat_id = "";
                $cat_id = fp_get_settings('fp_ticker_cat');

                $args = array(
                    'cat' => $cat_id,
                    'post_status' => 'publish',
                    'ignore_sticky_posts' => 1,
                    'posts_per_page' => 10
                );
            ?>
            <?php $query = new WP_Query( $args ); ?>
                <?php if ( $query -> have_posts() ) : ?>
                    <?php while ( $query -> have_posts() ) : $query -> the_post(); ?>
                        <li>
                            <a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a>
                            <div class="sep"></div>
                        </li>                           
                    <?php endwhile; ?>
                <?php endif; ?>
            <?php wp_reset_query();?>

Also the JS script loaded for news ticker as following

jQuery.fn.liScroll = function(settings) {
    settings = jQuery.extend({
    travelocity: 0.07
    }, settings);       
    return this.each(function(){
            var $strip = jQuery(this);
            $strip.addClass("newsticker")
            var stripWidth = 1;
            $strip.find("li").each(function(i){
            stripWidth += jQuery(this, i).outerWidth(true); // thanks to Michael Haszprunar and Fabien Volpi
            });
            var $mask = $strip.wrap("<div class='mask'></div>");
            var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");                             
            var containerWidth = $strip.parent().parent().width();  //a.k.a. 'mask' width   
            $strip.width(stripWidth);           
            var totalTravel = stripWidth+containerWidth;
            var defTiming = totalTravel/settings.travelocity;   // thanks to Scott Waye     
            function scrollnews(spazio, tempo){
            $strip.animate({right: '-='+ spazio}, tempo, "linear", function(){$strip.css("left", containerWidth); scrollnews(totalTravel, defTiming);});
            }
            scrollnews(totalTravel, defTiming);             
            $strip.hover(function(){
            jQuery(this).stop();
            },
            function(){
            var offset = jQuery(this).offset();
            var residualSpace = offset.right + stripWidth;
            var residualTime = residualSpace/settings.travelocity;
            scrollnews(residualSpace, residualTime);
            });         
    }); 
  };

Any help guys?

Mayeenul Islam
  • 4,532
  • 5
  • 49
  • 102
  • A solution could be to check if you are at the last image and then set the counter back at 0 (offset, residualSPace and residualTime). – Mandy Schoep Jan 18 '14 at 14:39
  • [Turn on error reporting](http://stackoverflow.com/questions/6575482/how-do-i-enable-error-reporting-in-php) and invest in an IDE with error highlighting – danronmoon Jan 18 '14 at 14:41

1 Answers1

0

If you want an infinite loop, enclose the while look you currently have inside a while (true) block that "wraps" the inside while loop.

And just a tip: If you have PHP code spanning multiple lines, no need to explicitly state <?php...?> every line; PHP code can span multiple lines, and it will make your code easier to read in the long run.

Mike Koch
  • 1,540
  • 2
  • 17
  • 23