This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!

Untitled

By: Eckstein on Dec 17th, 2012  |  syntax: PHP  |  size: 11.26 KB  |  views: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  /**
  3.  * Template Name: The Vine
  4.  *
  5.  * @package WordPress
  6.  * @subpackage Twenty_Eleven
  7.  * @since Twenty Eleven 1.0
  8.  */
  9. ?>
  10.  
  11. <?php
  12. //Form Processing-----------------------------------------------------------------
  13.  
  14.  
  15. //Display chosen number of posts per page
  16. $gridperpage = array("8", "16", "32", "64", "96");
  17. $listperpage = array("10", "20", "40", "65", "100");
  18. $perpagecurrent = $_POST['perpage'];
  19.  
  20.         //If the number is already set, use it
  21. if (isset($_POST['perpage'])) {
  22.         $perpage = $_POST['perpage'];
  23.         }
  24.         //If the number of posts matches the multiples of the grid numbers AND we're on the list page, switch the count to 20
  25. if ((!in_array($perpagecurrent, $listperpage)) && (($_POST['view']) == 'list') ){
  26.         $perpage = '20';
  27.         }
  28.         //If we're on the grid page and the number is a multiple from the list page, switch to 32. Also do this if there is no value set yet since the default view is the grid
  29. elseif (((!in_array($perpagecurrent, $gridperpage)) && (($_POST['view']) == 'grid')) || (!$_POST['perpage']) ){
  30.         $perpage = '32';
  31.         }
  32.  
  33.  
  34. //Display chosen post types
  35.  
  36. if ((!$_POST['userposts']) && (!$_POST['posts'])) :
  37.         $posttype= array('tsv_userpost', 'post');
  38. elseif ((($_POST['userposts']) == 'true') && (($_POST['posts']) == 'true')) :
  39.         $posttype= array('tsv_userpost', 'post');
  40. elseif ((($_POST['userposts']) == 'true') && (($_POST['posts']) == '')) :
  41.         $posttype= 'tsv_userpost';
  42. elseif ((($_POST['userposts']) == '') && (($_POST['posts']) == 'true')) :
  43.         $posttype= 'post';
  44. endif;
  45.  
  46.  
  47. //Display only selected User Post Categories
  48.   if (isset($_POST['showvideos']) && ($_POST['showvideos'] == 'true')) {
  49.     $cats[]='user-video';
  50. } if (isset($_POST['showimages']) && ($_POST['showimages'] == 'true')) {
  51.     $cats[]='user-image';
  52. } if (isset($_POST['showaudio']) && ($_POST['showaudio'] == 'true')) {
  53.     $cats[]='user-audio';
  54. } if (isset($_POST['showwriting']) && ($_POST['showwriting'] == 'true')) {
  55.     $cats[]='user-writing';
  56. } if (isset($_POST['showevents']) && ($_POST['showevents'] == 'true')) {
  57.     $cats[]='user-event';
  58. };
  59.  
  60. $upostcat = implode(',',$cats); //Put all the selected categories into the $upostcat array
  61. ?>
  62.  
  63.  
  64. <?php
  65. //Sort posts by selected method
  66.  
  67. if (isset($_POST['sortby']) && ($_POST['sortby'] == 'date')) {
  68.         $sortmetakey='';
  69.         $sortby='date';
  70.         }
  71. elseif (isset($_POST['sortby']) && ($_POST['sortby'] == 'rating')) {
  72.         $sortmetakey='ratings_average';
  73.         $sortby='meta_value_num date';
  74.         }
  75. elseif (isset($_POST['sortby']) && ($_POST['sortby'] == 'favscount')) {
  76.         $sortmetakey='wpfp_favorites';
  77.         $sortby='meta_value_num date';
  78.         }
  79. elseif (isset($_POST['sortby']) && ($_POST['sortby'] == 'viewcount')) {
  80.         $sortmetakey='_count-views_all';
  81.         $sortby='meta_value_num date';
  82.         };
  83.         ?>
  84.  
  85.  
  86.  
  87.  
  88. <?php //Start of content
  89. get_header(); ?>
  90.  
  91.  
  92.  
  93.  
  94.  
  95. <div id="vine-menu">
  96.  
  97. <?php //Search the vine ?>
  98. <div class="vine-search">
  99.         <form method="get" id="searchform" action="<?php echo esc_url( home_url( '/' ) ); ?>">
  100.                 <label for="s" class="assistive-text"><?php _e( 'Search', 'twentyeleven' ); ?></label>
  101.                 <input type="text" class="field" name="s" id="vinesearch" placeholder="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
  102.                 <input type="submit" class="submit" name="submit" id="searchsubmit" value="<?php esc_attr_e( 'Search', 'twentyeleven' ); ?>" />
  103.         </form>
  104. </div>
  105.  
  106.        
  107.        
  108. <?php //Browse the vine ?>
  109.  
  110.  
  111. <?php
  112. //Start filter menu            
  113. ?>
  114.         <form method="post" id="vine-sort-form" >
  115.         <?php  
  116.         if ($_SERVER['REQUEST_METHOD']!='POST') {
  117.                 $notsubmitted='checked';
  118.                 $notsubmitted_dd='selected';
  119.         };
  120.         //Auto-select all post types when user first selects to show userposts 
  121.         if ('true' == ($_POST['userposts']) && ('' == ($_POST['showvideos'])) && ('' == ($_POST['showaudio'])) && ('' == ($_POST['showimages'])) && ('' == ($_POST['showwriting'])) && ('' == ($_POST['showevents'])) ) {
  122.                 $userpostselected='checked';
  123.                 };
  124.         //Dont allow both post types to go unselected
  125.         if ('true' != ($_POST['userposts']) && ('true' != ($_POST['posts']))) {
  126.                 $noselectnone='checked';
  127.                 };
  128.         ?>
  129.  
  130.        
  131.         <?php//Choose View ?>
  132.         <?php
  133.         if (($_POST['view'] == 'grid') || (!isset($_POST['view']))) { ?>
  134.         <input id="viewgrid" type="radio" name="view" value="grid" onclick="this.form.submit()" <?php if ('grid' == ($_POST['view'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; endif ?> style="display:none;">
  135.         <label class="imagelabel" id="gridchecked" for="viewgrid"><img src="/wordpress/image/icons/grid-on.png" /></label>
  136.         <?php }
  137.         else { ?>      
  138.         <input id="viewgrid" type="radio" name="view" value="grid" onclick="this.form.submit()" <?php if ('grid' == ($_POST['view'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; endif ?> style="display:none;">
  139.         <label class="imagelabel" id="gridunchecked" for="viewgrid"><img src="/wordpress/image/icons/grid-off.png" /></label>
  140.         <?php } ?>
  141.        
  142.         <?php
  143.         if ($_POST['view'] == 'list') { ?>
  144.         <input id="viewlist" type="radio" name="view" value="list" onclick="this.form.submit()" <?php if ('list' == ($_POST['view'])) : echo 'checked'; endif ?> style="display:none;">
  145.         <label id="listchecked" class="imagelabel" for="viewlist"><img src="/wordpress/image/icons/list-on.png" /></label>
  146.         <?php }
  147.         else { ?>
  148.         <input id="viewlist" type="radio" name="view" value="list" onclick="this.form.submit()" <?php if ('list' == ($_POST['view'])) : echo 'checked'; endif ?> style="display:none;">
  149.         <label id="listunchecked" class="imagelabel" for="viewlist"><img src="/wordpress/image/icons/list-off.png" /></label>
  150.         <?php } ?>
  151.        
  152.         <br />
  153.        
  154.         <div class="vine-menu-heading">Per page:</div>
  155.        
  156.         <?php if ((($_POST['view']) == 'grid') || (!isset($_POST['perpage']))) { ?>
  157.        
  158.         <select name="perpage" id="perpage">
  159.                 <option value="8" <?php if ('8' == ($_POST['perpage'])) : echo 'selected="selected"'; endif; ?> onclick="this.form.submit()">2 rows (8)</option>
  160.                 <option value="16" <?php if ('16' == ($_POST['perpage'])) : echo 'selected="selected"'; endif; ?> onclick="this.form.submit()">4 rows (16)</option>
  161.                 <option value="32" <?php if ('32' == ($_POST['perpage'])) : echo 'selected="selected"'; elseif ((in_array($perpagecurrent, $listperpage))) : echo 'selected="selected"'; elseif (!$_POST['perpage']) : echo 'selected="selected"'; endif;?> onclick="this.form.submit()">8 rows (32)</option>
  162.                 <option value="64" <?php if ('64' == ($_POST['perpage'])) : echo 'selected="selected"'; endif;?> onclick="this.form.submit()">16 rows (64)</option>
  163.                 <option value="96" <?php if ('96' == ($_POST['perpage'])) : echo 'selected="selected"'; endif;?> onclick="this.form.submit()">24 rows (96)</option>
  164.         </select>
  165.         <?php }
  166.         else { ?>
  167.         <select name="perpage" id="perpage">
  168.                 <option value="10" <?php if ('10' == ($_POST['perpage'])) : echo 'selected="selected"'; endif; ?> onclick="this.form.submit()">10 posts</option>
  169.                 <option value="20" <?php if ('20' == ($_POST['perpage'])) : echo 'selected="selected"'; elseif ((in_array($perpagecurrent, $gridperpage))) : echo 'selected="selected"'; elseif (!$_POST['perpage']) : echo 'selected="selected"'; endif; ?> onclick="this.form.submit()">20 posts</option>
  170.                 <option value="40" <?php if ('40' == ($_POST['perpage'])) : echo 'selected="selected"';  endif;?> onclick="this.form.submit()">40 posts</option>
  171.                 <option value="65" <?php if ('65' == ($_POST['perpage'])) : echo 'selected="selected"'; endif;?> onclick="this.form.submit()">65 posts</option>
  172.                 <option value="100" <?php if ('100' == ($_POST['perpage'])) : echo 'selected="selected"'; endif;?> onclick="this.form.submit()">100 posts</option>
  173.         </select>
  174.         <?php } ?>
  175.        
  176.         <div class="vine-menu-heading">Sort by:</div>
  177.         <input type="radio" name="sortby" value="date" onclick="this.form.submit()" <?php if ('date' == ($_POST['sortby'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; endif;  ?>>Date<br />
  178.         <input type="radio" name="sortby" value="rating" onclick="this.form.submit()" <?php if ('rating' == ($_POST['sortby'])) : echo 'checked'; endif ?>>Rating<br />
  179.         <input type="radio" name="sortby" value="favscount" onclick="this.form.submit()" <?php if ('favscount' == ($_POST['sortby'])) : echo 'checked'; endif ?>># of Favs<br />
  180.         <input type="radio" name="sortby" value="viewcount" onclick="this.form.submit()" <?php if ('viewcount' == ($_POST['sortby'])) : echo 'checked'; endif ?>># of Views<br />
  181.        
  182.         <div class="vine-menu-heading">Post Type:</div>
  183.         <input type="checkbox" name="posts" value="true" onclick="this.form.submit()" <?php if ('true' == ($_POST['posts'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; elseif($noselectnone) : echo $noselectnone; endif;?>>Featured Posts<br />
  184.         <input type="checkbox" name="userposts" value="true" onclick="this.form.submit()" <?php if ('true' == ($_POST['userposts'])) : echo 'checked';  elseif ($notsubmitted) : echo $notsubmitted; elseif($noselectnone) : echo $noselectnone; endif; ?>>User Posts<br />
  185.                
  186.                
  187.                 <div class="user-cat-select">
  188.                 <?php
  189.                 if ('true' == ($_POST['userposts'])) {
  190.                         if ('' == ($_POST['posts'])) { ?>
  191.                 <input type="checkbox" name="showvideos" value="true" onclick="this.form.submit()" <?php if ('true' == ($_POST['showvideos'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; elseif ($userpostselected) : echo $userpostselected; endif; ?>>Video<br />
  192.                 <input type="checkbox" name="showimages" value="true" onclick="this.form.submit()" <?php if ('true' == ($_POST['showimages'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; elseif ($userpostselected) : echo $userpostselected; endif; ?>>Images<br />
  193.                 <input type="checkbox" name="showwriting" value="true" onclick="this.form.submit()" <?php if ('true' == ($_POST['showwriting'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; elseif ($userpostselected) : echo $userpostselected; endif; ?>>Writing<br />
  194.                 <input type="checkbox" name="showaudio" value="true" onclick="this.form.submit()" <?php if ('true' == ($_POST['showaudio'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; elseif ($userpostselected) : echo $userpostselected; endif; ?>>Audio<br />
  195.                 <input type="checkbox" name="showevents" value="true" onclick="this.form.submit()" <?php if ('true' == ($_POST['showevents'])) : echo 'checked'; elseif ($notsubmitted) : echo $notsubmitted; elseif ($userpostselected) : echo $userpostselected; endif; ?>>Events<br />
  196.                 <?php }
  197.                 }?>
  198.                 </div>         
  199.         </form>
  200.        
  201.        
  202.  
  203.        
  204.  
  205.        
  206.  
  207.  
  208.  
  209.  
  210.  
  211. </div><?php //.thevinemenu ?>
  212.  
  213.  
  214. <div class="vine-display">     
  215.  
  216.                 <?php
  217.                 // The Query  
  218.  
  219.                         $counter = 1;
  220.                         $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
  221.                         $the_query = new WP_Query( array(
  222.                                 'post_type'=> $posttype,
  223.                                 'posts_per_page'=>$perpage,
  224.                                 'paged'=> $paged,
  225.                                 'category_name'=>$upostcat,
  226.                                 'meta_key' =>$sortmetakey,
  227.                                 'orderby' =>$sortby,
  228.                                 'order'=> 'DESC'
  229.                                 )
  230.                         );
  231.        
  232. //Top Navigation
  233.         wp_pagenavi( array( 'query' => $the_query ) );
  234.  
  235. //Start loop
  236.  
  237.                 while ( $the_query->have_posts() ) :
  238.                 $the_query->the_post();
  239.                
  240.                
  241.                 if ('grid' == ($_POST['view']) || ($_SERVER['REQUEST_METHOD']!='POST')) : get_template_part('the-vine', 'grid');
  242.                 elseif ('list' == ($_POST['view'])) : get_template_part('the-vine', 'list');
  243.                 endif;
  244.                        
  245. ?>     
  246.        
  247. <?php endwhile; ?>
  248.        
  249. <div class="wp-page-navi-bottom"><?php wp_pagenavi( array( 'query' => $the_query ) ); ?></div>
  250.        
  251. <?php wp_reset_query(); ?>
  252.  
  253.  
  254.  
  255. </div>
  256.  
  257.  
  258.  
  259. <?php  get_footer(); ?>
clone this paste RAW Paste Data