Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: Gallery Template
- */
- ?>
- <?php get_header();
- global $post;
- global $wpdb;
- global $wp_query;
- global $parent_id;
- global $cat_value;
- global $query_parent_id;
- global $query_parent_title;
- $gallery_page = '/projects/';
- $category_page = '/projects-by-category/';
- $all_albums = 'All Projects »';
- $all_categories = 'Projects by Category »';
- $request = parse_url($_SERVER['REQUEST_URI']);
- $path = $request["path"];
- // Set up the query
- $parents = $wpdb->get_results("SELECT post_title, id FROM wp_posts WHERE (post_parent = 0 AND post_type = 'gallery' AND post_status = 'publish')");
- ?>
- <div id="container" class="site-content gallery-album-template">
- <div id="content" class="hentry">
- <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>
- <h1 class="home_page_title entry-header"><?php the_title(); ?><?php if(isset($_GET['cat'])) { echo ' | ' . ucwords($_GET['cat']); } ?></h1>
- <?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' ); ?>
- <div class="gallery_box entry-content">
- <ul>
- <?php
- // get array values for post_title and id
- foreach($parents as $parent) {
- $query_parent_id = $parent->id;
- $query_parent_title = strtolower($parent->post_title);
- if(isset($_GET['cat'])) {
- $cat_value = $_GET['cat'];
- // compare the queried parent_title with the query string value, then assign its id to $parent_id
- if($query_parent_title==$cat_value) { $parent_id = $query_parent_id; }
- } elseif(!isset($_GET['cat']) && $path==$category_page) {
- $parent_id = 0;
- }
- }
- $paged = $wp_query->query_vars["paged"];
- $permalink = get_permalink();
- $gllr_options = get_option( 'gllr_options' );
- if( substr( $permalink, strlen( $permalink ) -1 ) != "/" )
- {
- if( strpos( $permalink, "?" ) !== false ) {
- $permalink = substr( $permalink, 0, strpos( $permalink, "?" ) -1 )."/";
- }
- else {
- $permalink .= "/";
- }
- }
- $count = 0;
- // post_parent was added and assigned the value $parent_id
- $args = array(
- 'post_type' => 'gallery',
- 'post_status' => 'publish',
- 'orderby' => 'post_date',
- 'posts_per_page' => -1,
- 'post_parent' => $parent_id
- );
- $second_query = new WP_Query( $args );
- if ( function_exists( 'pdfprnt_show_buttons_for_custom_post_type' ) ) echo pdfprnt_show_buttons_for_custom_post_type( $second_query );
- $count_all_albums = count($second_query->posts);
- $per_page = $showitems = get_option( 'posts_per_page' );
- if( $paged != 0 )
- $start = $per_page * ($paged - 1);
- else
- $start = $per_page * $paged;
- if ($second_query->have_posts()) : while ($second_query->have_posts()) : $second_query->the_post();
- if( $count < $start ) {
- $count++;
- continue;
- }
- if( ( $count - $start ) > $per_page -1 )
- break;
- $attachments = get_post_thumbnail_id( $post->ID );
- if( empty ( $attachments ) ) {
- $attachments = get_children( 'post_parent='.$post->ID.'&post_type=attachment&post_mime_type=image&numberposts=1' );
- $id = key($attachments);
- $image_attributes = wp_get_attachment_image_src( $id, 'album-thumb' );
- }
- else {
- $image_attributes = wp_get_attachment_image_src( $attachments, 'album-thumb' );
- }
- if( 1 == $gllr_options['border_images'] ){
- $gllr_border = 'border-width: '.$gllr_options['border_images_width'].'px; border-color:'.$gllr_options['border_images_color'].'; padding:0;';
- $gllr_border_images = $gllr_options['border_images_width'] * 2;
- }
- else{
- $gllr_border = 'padding:0;';
- $gllr_border_images = 0;
- }
- if($post->post_parent !=0):
- $count++;
- ?>
- <li>
- <a href="<?php echo $permalink; echo basename( get_permalink( $post->ID ) ); ?>">
- <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]; ?>" />
- <div class="gallery_detail_box">
- <div><?php echo $post->post_title; ?></div>
- <!--<div><?php #echo the_excerpt_max_charlength(100); ?></div>-->
- <?php #echo $gllr_options["read_more_link_text"]; ?>
- </div>
- </a>
- </li>
- <?php endif;
- if($post->post_parent == 0 && $path == $category_page) :
- $count++; ?>
- <li>
- <a href="?cat=<?php echo strtolower($post->post_title); ?>">
- <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]; ?>" />
- <div class="gallery_detail_box">
- <div><?php echo $post->post_title; ?></div>
- </div>
- </a>
- </li>
- <?php endif;
- endwhile; endif; wp_reset_query(); ?>
- </ul>
- <?php
- if( $paged == 0 )
- $paged = 1;
- $pages = intval ( $count_all_albums/$per_page );
- if( $count_all_albums % $per_page > 0 )
- $pages +=1;
- $range = 100;
- if( ! $pages ) {
- $pages = 1;
- }
- if( 1 != $pages ) {
- echo "</div><div class='clear'></div><div class='pagination'>";
- for ( $i = 1; $i <= $pages; $i++ ) {
- if ( 1 != $pages && ( !( $i >= $paged + $range + 1 || $i <= $paged - $range - 1 ) || $pages <= $showitems ) ) {
- echo ( $paged == $i ) ? "<span class='current'>". $i ."</span>":"<a href='". get_pagenum_link($i) ."' class='inactive' >". $i ."</a>";
- }
- }
- echo "<div class='clear'></div></div>\n";
- } else {?>
- </div>
- <?php } ?>
- </div>
- </div>
- <?php get_sidebar(); ?>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement