Advertisement
Guest User

Untitled

a guest
Jan 18th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.19 KB | None | 0 0
  1. function custom_query_shortcode($atts) {
  2.     // EXAMPLE USAGE:
  3.     // [loop the_query="showposts=100&post_type=page&post_parent=453"]
  4.  
  5.     // Defaults
  6.     extract(shortcode_atts(array(
  7.     "the_query" => ''
  8.     ), $atts));
  9.  
  10.     // de-funkify query
  11.     $the_query = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $the_query);
  12.     $the_query = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $the_query);
  13.  
  14.     // query is made              
  15.     query_posts($the_query);
  16.  
  17.     // Reset and setup variables
  18.     $output = '';
  19.     $temp_title = '';
  20.     $temp_link = '';
  21.  
  22.     // the loop
  23.     if (have_posts()) : while (have_posts()) : the_post();
  24.  
  25.         $temp_title = get_the_title($post->ID);
  26.         $temp_link = get_permalink($post->ID);
  27.        
  28.         // output all findings - CUSTOMIZE TO YOUR LIKING
  29.         $output.='<div class="one-sixth">';
  30.         $output.='<p><a href="'.$temp_link.'">'.$temp_title.'</a></p>';
  31.         $output.='<p><a href="'.genesis_get_custom_field('host_url').'">'.genesis_get_custom_field('host_url').'</a></p>';
  32.         $output.='</div>';
  33.  
  34.     endwhile;
  35.         $output.='<div class="clear-line"></div>';
  36.     else:
  37.  
  38.         $output.='nothing found.';
  39.  
  40.     endif;
  41.  
  42.     wp_reset_query();
  43.     return $output;
  44. }
  45. add_shortcode("loop", "custom_query_shortcode");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement