Breaking News ticker Easy

Post To Breaking News that allows you to display unlimited number of breaking news in your website.

<?php 
	global $post;
	$original_post = $post;
	$cat 				= '1';
	$number 			= '10';	
	$timeout 			= '3500';

	if( !$number || $number == ' ' || !is_numeric($number) ) $number = 5;	
	if( !$timeout || $timeout == ' ' || !is_numeric($timeout))	$timeout = 3500; 

	?>
	
	<div class="clear"></div>
	<div id="breaking-news" class="breaking-news">
		<span class="breaking-news-title"><?php echo  esc_html__( 'Breaking News' , 'text_domain') ; ?></span>
		
		<?php		
			
		$args = array('category__in' => $cat, 'posts_per_page'=> $number, 'no_found_rows' => 1 );			

		$breaking_query = new wp_query( $args  );
			
		if( $breaking_query->have_posts() ) : $count=0; ?>
			<ul>
				<?php
				while( $breaking_query->have_posts() ) :
					$breaking_query->the_post();
					$count++;
				?>
					<li><a href="<?php the_permalink()?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
				<?php
				endwhile;
				$post = $original_post;
				wp_reset_query();
				?>
			</ul>
		<?php endif; ?>
		
		
		<style type="text/css">
			.breaking-news{
				position: relative; width: 100%;
    			display: inline-block;
    		}
			.breaking-news span.breaking-news-title {
			    background: #F43D2A;
			    display: block;
			    float: left;
			    padding: 8px 10px 0;
			    height: 32px;
			    color: #FFF;			    
			    font-size: 14px;
			}
			.breaking-news ul {
			     position: absolute;top: 0;left: 118px; padding-left: 0;
			}
			.breaking-news ul a {
			    padding: 8px;
			    display: block;
			    white-space: nowrap;			    
			    background: #FFF;
			}
		</style>

		<script type="text/javascript">		
			// Breaking News
			function createTicker(){
				var tickerLIs 	= jQuery("#breaking-news ul").children();
				tickerItems 	= new Array();
				tickerLIs.each(function(el) {
					tickerItems.push( jQuery(this).html() );
				});
				i = 0  ;
				rotateTicker();
			}
			var isInTag = false;
			function typetext() {
				var $breaking_news = jQuery('#breaking-news ul');
				if( $breaking_news.length > 0 ){
					var thisChar = tickerText.substr(c, 1);
					if( thisChar == '<' ){ isInTag = true; }
					if( thisChar == '>' ){ isInTag = false; }
					$breaking_news.html(tickerText.substr(0, c++));
					if(c < tickerText.length+1)
						if( isInTag ){
							typetext();
						}else{
							setTimeout("typetext()", 35);
						}
					else {
						c = 1;
						tickerText = "";
					}
				}
			}

			jQuery(document).ready(function(){
				
				createTicker(); 				
				
			});
			
			function rotateTicker(){                                   
				if( i == tickerItems.length ){ i = 0; }                                                         
				tickerText = tickerItems[i];                              
				c = 0;                                                    
				typetext();                                               
				setTimeout( "rotateTicker()", <?php echo $timeout ?> );                     
				i++;                                                      
			}                                                           
			
		</script>
	</div> <!-- .breaking-news -->