Display current page childrens

24/02/2012

Top section code

<?php 
get_header();
global $xyz_queried_object_id, $wp_query;
$xyz_queried_object_id = $wp_query->get_queried_object_id();
?>

Add this code inside the template page or in the sidebar.

<?php
global $xyz_queried_object_id;
$subpages = new WP_Query(array('post_type'=>'page','post_parent'=>$xyz_queried_object_id)); 
while( $subpages->have_posts() ) {
$subpages->the_post();
?>
<h1><?php the_title(); ?></h1>
<article>
<?php the_content(); ?>
</article>
<?php 
}
?>

Display posts with a specific custom field and value

15/01/2012
<?php query_posts('meta_key=review_type&meta_value=movie'); 
if (have_posts()) : while (have_posts()) : the_post(); ?>

Insert custom content inside the loop

15/01/2012
<?php if (have_posts()) : 
$count = 0;
while (have_posts()) : the_post();
$count++;
if ($count == 2) : ?>
          //Paste your custom content code here
          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
          <?php the_excerpt(); ?>
   <?php else : ?>
          <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
          <?php the_excerpt(); endif; endwhile; endif; ?>

Use more than one loop on a page

15/01/2012

and without printing duplicate posts.

The first loop

<?php
query_posts('showposts=5');
$ids = array();
while (have_posts()) : the_post();
$ids[] = get_the_ID();
the_title();
the_content();
endwhile;
?>

And the second loop

<?php
query_posts(array('post__not_in' => $ids));
while (have_posts()) : the_post();
the_title();
the_content();
endwhile;
?>

Get posts published between two dates

15/01/2012
<?php
  function filter_where($where = '') {
        $where .= " AND post_date >= '2009-03-17' AND post_date <= '2009-05-03'";
    return $where;
  }
add_filter('posts_where', 'filter_where');
query_posts($query_string);
while (have_posts()) :
      the_post();
      the_content();
endwhile;
?>

Mullet loop code

15/01/2012

The mullet loop displays the full content for only the first post, and then displays only excerpts for all remaining posts.

<?php 
  // to count posts inside WP loop
  $postCount=0; 
  // number of full posts to display
  $displayNumPosts = 5; 
  // WP loop
  if(have_posts()) : while (have_posts()) : the_post(); 
      if($postCount<$displayNumPosts) {     
    ?>        
        <!-- TEMPLATE CODE TO SHOW FULL POST -->
        <a href="<?php the_permalink() ?>">
        <?php the_title(); ?>
        </a>
        <div class="content">
        <?php the_content(); ?>
        </div>    
    <?php } else { ?>
        <!-- TEMPLATE CODE TO SHOW MULLETED POST -->
        <?php the_time('M j, y') ?> 
        <a href="<?php the_permalink() ?>">
        <?php the_title(); ?>
        </a>        
    <?php } ?>    
    <?php     
      // increment $postCount
      $postCount++;   
    ?>
<?php
  // WP loop ends
  endwhile; endif;
?>

Custom breadcrumb navigation

15/01/2012
<?php 
  if ((is_page() && !is_front_page()) || is_home() || is_category() || is_single()) {
   echo '<ul id="breadcrumbs">';
   echo '<li class="front_page"><a href="'.get_bloginfo('url').'">Home</a></li>';
   $post_ancestors = get_post_ancestors($post);
   if ($post_ancestors) {
      $post_ancestors = array_reverse($post_ancestors);
      foreach ($post_ancestors as $crumb)
          echo '<li><a href="'.get_permalink($crumb).'">'.get_the_title($crumb).'</a></li>';
   }
   if (is_category() || is_single()) {
      $category = get_the_category();
      echo '<li><a href="'.get_category_link($category[0]->cat_ID).'">'.$category[0]->cat_name.'</a></li>';
   }
   if (!is_category())
      echo '<li class="current"><a href="'.get_permalink().'">'.get_the_title().'</a></li>';
   echo '</ul>';
} ?>

Display specific elements sequentially on scroll

07/01/2012
$(document).ready(function(){
 var window_y = 0;
  $(window).scroll(function(){
  window_y = $(window).scrollTop();
  var lis = $('#content .gallery li'); //replace here with your specific id and/or class
  var i = 0;
    if(window_y >= 250)
			{
      (function displayImages() {  
      lis.eq(i++).fadeIn(120, displayImages);  
      })();  
      }
  }).trigger('scroll');
});

And the basic CSS

#content .gallery li {display: none;}

Feature tours plugin

07/01/2012

Create jQuery Feature Tours in a Breeze with Joyride: read more

Trigger a slide out section

17/09/2010

First, we need a trigger somewhere in the page with the id “trigger”:

<div id="trigger">some content goes here</div>

Then, the code for the slide out section (the link with the class “close” will give the user the option to close the box and it will not appear again.)

<div id="slidebox">
	<a class="close">X</a>
	specific section content goes here
</div>

Some CSS

#slidebox{
    width:400px;
    height:100px;
    padding:10px;
    background-color:#fff;
    border-top:3px solid #E28409;
    position:fixed;
    bottom:0px;
    right:-430px;
    -moz-box-shadow:-2px 0px 5px #aaa;
    -webkit-box-shadow:-2px 0px 5px #aaa;
    box-shadow:-2px 0px 5px #aaa;
}

And the magic

<script type="text/javascript">
$(function() {
	$(window).scroll(function(){
		var distanceTop = $('#trigger').offset().top - $(window).height();
		if  ($(window).scrollTop() > distanceTop)
			$('#slidebox').animate({'right':'0px'},300);
		else
			$('#slidebox').stop(true).animate({'right':'-430px'},100);
	});
	$('#slidebox .close').bind('click',function(){
		$(this).parent().remove();
	});
});
</script>