Tag Archive for loop

javascript function within a function to repeat itself js jquery jq loop looping

// animation functions
		zlpFX = {
			show1: function() {
				$('div#mainBackground2').fadeOut(3000);
				$('div#transMoving').animate({
					paddingLeft: "180px",
					paddingTop: "20px"
				},
				4000).find('h3').fadeOut(2000);
				setTimeout("zlpFX.show2()", 14000);
			},
			show2: function() {
				$('div#mainBackground2').fadeIn(4000);
				$('div#transMoving').animate({
					paddingLeft: '220px',
					paddingTop: '75px'
				},
				4500).find('h3').fadeIn(6000);
				setTimeout("zlpFX.show1()", 14000);
			}
		};




		// now start the animation functions
		setTimeout("zlpFX.show1()", 11000);

source

Worpress rewind post

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

<!-- the loop --> 

or 


<?php rewind_posts(); ?>
<?php query_posts('category_name=CATEGORY&showposts=3'); ?>
<?php while (have_posts()) : the_post(); ?>

<!-- then the loop -->

source

Javascript – Reverse a String

var aString = "Hotel";
var rString = "";
for(var i = aString.length; i>=0; i--){
        rString += aString.substr(i,1);
}

source

Custom Query Shortcode: Run a Loop inside Any Post/Page

function custom_query_shortcode($atts) {

   // EXAMPLE USAGE:
   // [loop the_query="showposts=100&post_type=page&post_parent=453"]
   
   // Defaults
   extract(shortcode_atts(array(
      "the_query" => ''
   ), $atts));

   // de-funkify query
   $the_query = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("1"))', $the_query);
   $the_query = preg_replace('~&#0*([0-9]+);~e', 'chr(1)', $the_query);

   // query is made               
   query_posts($the_query);
   
   // Reset and setup variables
   $output = '';
   $temp_title = '';
   $temp_link = '';
   
   // the loop
   if (have_posts()) : while (have_posts()) : the_post();
   
      $temp_title = get_the_title($post->ID);
      $temp_link = get_permalink($post->ID);
      
      // output all findings - CUSTOMIZE TO YOUR LIKING
      $output .= "<li><a href='$temp_link'>$temp_title</a></li>";
          
   endwhile; else:
   
      $output .= "nothing found.";
      
   endif;
   
   wp_reset_query();
   return $output;
   
}
add_shortcode("loop", "custom_query_shortcode");




[loop the_query="showposts=20&post_type=page&post_parent=453&ord=ASC"]

source

Grab the first image from a post

// function
function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=['"]([^'"]+)['"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}

//template tag
<?php echo catch_that_image() ?>

source

Link title to external link

// function
function print_post_title() {
global $post;
    $thePostID = $post->ID;
    $post_id = get_post($thePostID);
    $title = $post_id->post_title;
    $perm = get_permalink($post_id);
    $post_keys = array(); $post_val = array();
    $post_keys = get_post_custom_keys($thePostID);

    if (!empty($post_keys)) {
foreach ($post_keys as $pkey) {
if ($pkey=='title_url') {
$post_val = get_post_custom_values($pkey);
}
}
if (empty($post_val)) {
$link = $perm;
} else {
$link = $post_val[0];
}
    } else {
$link = $perm;
    }
    echo '<h2><a href="'.$link.'" rel="bookmark" title="'.$title.'">'.$title.'</a></h2>';
}

// template tag

<?php print_post_title() ?>

source

Fastest loop

var i = array.length; while (i--) {
    // do something
}

source

Silverlight C# Sound Loop

//to add Event Handler where "ambient1" and "ambient2" are different media elements... 

ambient1.MediaEnded += new RoutedEventHandler(media_MediaEnded);
ambient2.MediaEnded += new RoutedEventHandler(media_MediaEnded);

//Event Handler

void media_MediaEnded(object sender, RoutedEventArgs e)
        {
            MediaElement ctrl = (MediaElement)sender;
            ctrl.Stop();
            ctrl.Play();
        }

source

drupal – find available variable names and content for node

<?php
foreach($node->content as $outerarray=>$outerarrayvalue)
{
	foreach($outerarrayvalue as $innerarray=>$innerarrayvalue)
	{
		foreach($innerarrayvalue as $centrearray=>$centrearrayvalue)
		{
			foreach($centrearrayvalue as $key => $value)
			{
			echo("<em>".$outerarray."["".$innerarray.""]["".$centrearray.""]["".$key.""] = </em><b>".$value."</b><br />");
			}
		}
	}
}
?>

source

WordPress Loop, Style displayed posts differently

<?php $my_query = new WP_Query('cat=10&showposts=4'); ?>
<?php $count = 0; ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
<?php $count++; ?>

<?php if ($count == 1) : ?>
<div id="featured">
<div class="span-24 last" id="details">HTML Ipsum Presents</div>
<!-- end details -->
<h2 class="clear"><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h2>
<p class="clear"><?php the_content('read more...'); ?></p>
</div>
<hr/>
<?php elseif ($count == 4) : ?>
<div class="span-8 last">
<h3><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3>
<p class="clear"><?php the_content('read more...'); ?></p>
</div>
<?php else : ?>
<div class="span-8 border">
<h3><a href="<?php the_permalink(); ?>" ><?php the_title(); ?></a></h3>
<p class="clear"><?php the_content('read more...'); ?></p>
</div>
<?php endif; ?>

<?php endwhile; ?>

source