Advertisement
Guest User

Pockets

a guest
Jul 1st, 2016
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. function custom_alsolikequery_shortcode($atts) {
  2.  
  3.  
  4. // EXAMPLE USAGE:
  5. // [loop the_query="showposts=100&post_type=page&post_parent=453"]
  6.  
  7. // Defaults
  8. extract(shortcode_atts(array(
  9. "the_query" => ''
  10. ), $atts));
  11.  
  12. // de-funkify query
  13. $the_query = preg_replace('~&#x0*([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $the_query);
  14. $the_query = preg_replace('~&#0*([0-9]+);~e', 'chr(\\1)', $the_query);
  15.  
  16. // query is made
  17.  
  18.  
  19.  
  20. remove_all_filters('posts_orderby');
  21. query_posts($the_query);
  22.  
  23. // Reset and setup variables
  24. $output = '';
  25. $temp_title = '';
  26. $temp_link = '';
  27. $temp_url = '';
  28.  
  29. // the loop
  30.  
  31. $exclude = $GLOBALS['current_id'];
  32.  
  33. $args = array(
  34.  
  35. 'post__not_in' => array($exclude), 'post_type'=>'our-work', 'orderby'=>'rand', 'posts_per_page'=>'3'
  36.  
  37.  
  38.  
  39. );
  40. query_posts($args);
  41. if ( have_posts() ) : while ( have_posts() ) : the_post();
  42.  
  43.  
  44.  
  45.  
  46.  
  47. $temp_title = get_the_title($post->ID);
  48. $temp_link = get_permalink($post->ID);
  49. $img_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
  50.  
  51.  
  52. // output all findings - CUSTOMIZE TO YOUR LIKING
  53. $output .= "<li class='workitem workitem2' style='background:url($img_url); background-repeat: no-repeat!important;
  54. background-size: cover!important;
  55. background-position: center center!important;'><a href='$temp_link'><span>$temp_title</span></a></li>
  56.  
  57.  
  58.  
  59. ";
  60.  
  61. endwhile; else:
  62.  
  63. $output .= "nothing found.";
  64.  
  65. endif;
  66.  
  67. wp_reset_query();
  68. return $output;
  69.  
  70. }
  71. add_shortcode("loopalsolike", "custom_alsolikequery_shortcode");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement