Advertisement
suebriquet

gallery-template.php for Wordpress Gallery plugin

Sep 24th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.08 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: Gallery Template
  4. */
  5. ?>
  6.  
  7. <?php get_header();
  8.     global $post;
  9.     global $wpdb;
  10.     global $wp_query;
  11.     global $parent_id;
  12.     global $cat_value;
  13.     global $query_parent_id;
  14.     global $query_parent_title;
  15.  
  16.     $gallery_page = '/projects/';
  17.     $category_page = '/projects-by-category/';
  18.     $all_albums = 'All Projects &raquo;';
  19.     $all_categories = 'Projects by Category &raquo;';
  20.  
  21.     $request = parse_url($_SERVER['REQUEST_URI']);
  22.     $path = $request["path"];
  23.  
  24.     // Set up the query
  25.     $parents = $wpdb->get_results("SELECT post_title, id FROM  wp_posts WHERE (post_parent = 0 AND  post_type =  'gallery' AND  post_status =  'publish')");
  26.  
  27. ?>
  28.     <div id="container" class="site-content gallery-album-template">
  29.         <div id="content" class="hentry">
  30.             <p class="breadcrumb"><?php if(isset($_GET['cat'])) { ?><a href="<?php echo $gallery_page?>"><?php echo $all_albums; ?></a><?php } ?> <a href="<?php echo $category_page?>"><?php echo $all_categories; ?></a></p>
  31.             <h1 class="home_page_title entry-header"><?php the_title(); ?><?php if(isset($_GET['cat'])) { echo ' | ' . ucwords($_GET['cat']); } ?></h1>
  32.             <?php if ( function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) echo pdfprnt_show_buttons_for_custom_post_type( 'post_type=gallery&orderby=post_date' ); ?>
  33.             <div class="gallery_box entry-content">
  34.                 <ul>
  35.                 <?php
  36.  
  37.                     // get array values for post_title and id
  38.                     foreach($parents as $parent) {
  39.                         $query_parent_id = $parent->id;
  40.                         $query_parent_title = strtolower($parent->post_title);
  41.                         if(isset($_GET['cat'])) {
  42.                             $cat_value = $_GET['cat'];
  43.                             // compare the queried parent_title with the query string value, then assign its id to $parent_id
  44.                             if($query_parent_title==$cat_value) { $parent_id = $query_parent_id; }
  45.                         } elseif(!isset($_GET['cat']) && $path==$category_page) {
  46.                             $parent_id = 0;
  47.                         }
  48.                     }
  49.  
  50.                     $paged = $wp_query->query_vars["paged"];
  51.                     $permalink = get_permalink();
  52.                     $gllr_options = get_option( 'gllr_options' );
  53.                     if( substr( $permalink, strlen( $permalink ) -1 ) != "/" )
  54.                     {
  55.                         if( strpos( $permalink, "?" ) !== false ) {
  56.                             $permalink = substr( $permalink, 0, strpos( $permalink, "?" ) -1 )."/";
  57.                         }
  58.                         else {
  59.                             $permalink .= "/";
  60.                         }
  61.                     }
  62.                     $count = 0;
  63.                     // post_parent was added and assigned the value $parent_id
  64.                     $args = array(
  65.                         'post_type'                 => 'gallery',
  66.                         'post_status'               => 'publish',
  67.                         'orderby'                       => 'post_date',
  68.                         'posts_per_page'        => -1,
  69.                         'post_parent'   => $parent_id
  70.                     );
  71.                     $second_query = new WP_Query( $args );
  72.                     if ( function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) echo pdfprnt_show_buttons_for_custom_post_type( $second_query );
  73.                     $count_all_albums = count($second_query->posts);
  74.                     $per_page = $showitems = get_option( 'posts_per_page' );  
  75.                     if( $paged != 0 )
  76.                         $start = $per_page * ($paged - 1);
  77.                     else
  78.                         $start = $per_page * $paged;
  79.                     if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post();
  80.                         if( $count < $start ) {
  81.                             $count++;
  82.                             continue;
  83.                         }
  84.                         if( ( $count - $start ) > $per_page -1 )
  85.                             break;
  86.  
  87.                     $attachments    = get_post_thumbnail_id( $post->ID );
  88.                     if( empty ( $attachments ) ) {
  89.                         $attachments = get_children( 'post_parent='.$post->ID.'&post_type=attachment&post_mime_type=image&numberposts=1' );
  90.                         $id = key($attachments);
  91.                         $image_attributes = wp_get_attachment_image_src( $id, 'album-thumb' );
  92.                     }
  93.                     else {
  94.                         $image_attributes = wp_get_attachment_image_src( $attachments, 'album-thumb' );
  95.                     }
  96.                     if( 1 == $gllr_options['border_images'] ){
  97.                         $gllr_border = 'border-width: '.$gllr_options['border_images_width'].'px; border-color:'.$gllr_options['border_images_color'].'; padding:0;';
  98.                         $gllr_border_images = $gllr_options['border_images_width'] * 2;
  99.                     }
  100.                     else{
  101.                         $gllr_border = 'padding:0;';
  102.                         $gllr_border_images = 0;
  103.                     }
  104.                    
  105.                     if($post->post_parent !=0):
  106.                     $count++;
  107.                 ?>
  108.                     <li>                       
  109.                         <a href="<?php echo $permalink; echo basename( get_permalink( $post->ID ) ); ?>">
  110.                         <img style="width:<?php echo $gllr_options['gllr_custom_size_px'][0][0]; ?>px; <?php echo $gllr_border; ?>" alt="<?php echo $post->post_title; ?>" title="<?php echo $post->post_title; ?>" src="<?php echo $image_attributes[0]; ?>" />
  111.                         <div class="gallery_detail_box">
  112.                             <div><?php echo $post->post_title; ?></div>
  113.                             <!--<div><?php #echo the_excerpt_max_charlength(100); ?></div>-->
  114.                             <?php #echo $gllr_options["read_more_link_text"]; ?>
  115.                         </div>
  116.                         </a>
  117.                     </li>
  118.                 <?php endif;
  119.                 if($post->post_parent == 0 && $path == $category_page) :
  120.                     $count++; ?>
  121.                     <li>                       
  122.                         <a href="?cat=<?php echo strtolower($post->post_title); ?>">
  123.                         <img style="width:<?php echo $gllr_options['gllr_custom_size_px'][0][0]; ?>px; <?php echo $gllr_border; ?>" alt="<?php echo $post->post_title; ?>" title="<?php echo $post->post_title; ?>" src="<?php echo $image_attributes[0]; ?>" />
  124.                         <div class="gallery_detail_box">
  125.                             <div><?php echo $post->post_title; ?></div>
  126.                         </div>
  127.                         </a>
  128.                     </li>
  129.                 <?php endif;
  130.  
  131.                 endwhile; endif; wp_reset_query(); ?>
  132.                 </ul>
  133.                 <?php
  134.                     if( $paged == 0 )
  135.                             $paged = 1;
  136.                     $pages = intval ( $count_all_albums/$per_page );
  137.                     if( $count_all_albums % $per_page > 0 )
  138.                         $pages +=1;
  139.                     $range = 100;
  140.                     if( ! $pages ) {
  141.                         $pages = 1;
  142.                     }
  143.                     if( 1 != $pages ) {
  144.                         echo "</div><div class='clear'></div><div class='pagination'>";
  145.                         for ( $i = 1; $i <= $pages; $i++ ) {
  146.                             if ( 1 != $pages && ( !( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
  147.                                 echo ( $paged == $i ) ? "<span class='current'>". $i ."</span>":"<a href='". get_pagenum_link($i) ."' class='inactive' >". $i ."</a>";
  148.                             }
  149.                         }
  150.  
  151.                         echo "<div class='clear'></div></div>\n";
  152.                     } else {?>
  153.                         </div>
  154.                     <?php } ?>
  155.         </div>
  156.     </div>
  157. <?php get_sidebar(); ?>
  158. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement