Skip to content

Commit 17c5617

Browse files
committed
Merge pull request dimsemenov#33 from ciotto/gallery_category_navigation_template
Gallery category navigation template
2 parents 2312492 + e9f74fa commit 17c5617

6 files changed

+289
-20
lines changed

content-categories-navigation.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* The template used for displaying gallery categories thumbnail in ds-gallery-categories-navigation-template.php
4+
*
5+
* @package dsframework
6+
* @since dsframework 1.0
7+
*/
8+
?>
9+
<a class="project-thumb" href="<?php echo $GLOBALS['category']->navigation_link; ?>" data-album-id="<?php echo $GLOBALS['category']->post_name; ?>">
10+
<div class="project-thumb-inside">
11+
<?php
12+
if ( has_post_thumbnail($post->ID) ) {
13+
the_post_thumbnail( 'gallery-thumb' );
14+
} else {
15+
$post_meta = get_post_custom();
16+
$post_meta = unserialize( $post_meta['dsframework-gallery'][0] );
17+
if( isset( $post_meta['attachment_urls'] ) ) {
18+
$image_urls = $post_meta['attachment_ids'];
19+
echo wp_get_attachment_image( $image_urls[0], 'gallery-thumb' );
20+
} else {
21+
echo '<div style="width: 360px; height: 250px; background: grey;">' . __('Album images not found.', 'dsframework') . '</div>';
22+
}
23+
}
24+
?>
25+
<h4 class="project-title"><?php echo $GLOBALS['category']->name; ?></h4>
26+
<p class="project-description"><?php echo $GLOBALS['category']->description; ?></p>
27+
</div>
28+
</a>

content-masonry.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* The template used for displaying gallery thumbnail in ds-gallery-masonry-template.php and in ds-gallery-categories-navigation-template.php
4+
*
5+
* @package dsframework
6+
* @since dsframework 1.0
7+
*/
8+
?>
9+
<a class="project-thumb" href="<?php the_permalink(); ?>" data-album-id="<?php echo $post->post_name; ?>">
10+
<div class="project-thumb-inside">
11+
<?php
12+
if ( has_post_thumbnail($post->ID) ) {
13+
the_post_thumbnail( 'gallery-thumb' );
14+
} else {
15+
$post_meta = get_post_custom();
16+
$post_meta = unserialize( $post_meta['dsframework-gallery'][0] );
17+
if( isset( $post_meta['attachment_urls'] ) ) {
18+
$image_urls = $post_meta['attachment_ids'];
19+
echo wp_get_attachment_image( $image_urls[0], 'gallery-thumb' );
20+
} else {
21+
echo '<div style="width: 360px; height: 250px; background: grey;">' . __('Album images not found.', 'dsframework') . '</div>';
22+
}
23+
}
24+
?>
25+
<h4 class="project-title"><?php the_title(); ?></h4>
26+
<p class="project-description"><?php echo get_the_excerpt(); ?></p>
27+
</div>
28+
</a>

content-page-masonry.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* The template used for displaying page text in ds-gallery-masonry-template.php and in ds-gallery-categories-navigation-template.php
4+
*
5+
* @package dsframework
6+
* @since dsframework 1.0
7+
*/
8+
?>
9+
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
10+
<div class="entry-content">
11+
<h3><?php the_content(); ?></h3>
12+
</div>
13+
</article>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
*
4+
* Template Name: Gallery Categories Navigation Page
5+
*
6+
* The template for displaying gallery page with masonry layout.
7+
*
8+
* @package dsframework
9+
* @since dsframework 1.0
10+
*
11+
*/
12+
?>
13+
<?php get_header(); ?>
14+
<div id="primary" class="site-content">
15+
<div id="content" role="main">
16+
<?
17+
$permalink = get_permalink();
18+
$post_meta = get_post_custom();
19+
$visible_gallery_categories = array();
20+
21+
$gallery_category_slug="";
22+
if(isset($_GET) && isset($_GET['category'])) $gallery_category_slug=$_GET['category'];
23+
if($gallery_category_slug=="") $gallery_category_slug = $post_meta['dsframework-root-gallery-category'][0];
24+
if($gallery_category_slug=="" && isset($post_meta['dsframework-visible-gallery-categories'][0])) $visible_gallery_categories = explode(",", $post_meta['dsframework-visible-gallery-categories'][0]);
25+
26+
if(count($visible_gallery_categories)>0){
27+
foreach ( $visible_gallery_categories as $subgallery_category_slug ){
28+
$category=get_gallery_category_by_slug( trim( $subgallery_category_slug) );
29+
if($category!=null) $categories[]=$category;
30+
}
31+
}else if($gallery_category_slug!=""){
32+
$gallery_category=get_gallery_category_by_slug($gallery_category_slug);
33+
34+
$categories = get_gallery_categories(array('hide_empty' => 0, 'parent' => $gallery_category->term_id));
35+
}else{
36+
$categories = get_gallery_categories(array('hide_empty' => 0));
37+
}
38+
39+
40+
?>
41+
<section class="albums-thumbnails clearfix">
42+
<?php
43+
44+
45+
foreach ( $categories as $subcategory ) {
46+
$subcategory->navigation_link=add_query_arg( array('category' => $subcategory->slug), $permalink);
47+
$GLOBALS['category']=$subcategory;
48+
49+
if($subcategory->parent==0 || ($gallery_category_slug!="" && $subcategory->parent==$gallery_category->term_id) || count($visible_gallery_categories)>0){
50+
$postLoop = post_in_gallery_category( $subcategory, true );
51+
if( $postLoop->have_posts() ) {
52+
$postLoop->the_post();
53+
54+
get_template_part( 'content', 'categories-navigation' );
55+
56+
}
57+
}
58+
}
59+
60+
if(isset($gallery_category)){
61+
$postLoop = post_in_gallery_category( $gallery_category );
62+
63+
while ( $postLoop->have_posts() ) {
64+
$postLoop->the_post();
65+
get_template_part( 'content', 'masonry' );
66+
}
67+
}
68+
?>
69+
</section>
70+
<?php wp_reset_postdata(); ?>
71+
<?php get_template_part( 'content', 'page-masonry' ); ?>
72+
</div>
73+
</div>
74+
<?php get_sidebar(); ?>
75+
<?php get_footer(); ?>

ds-gallery-masonry-template.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,11 @@
3737
?>
3838
<section class="albums-thumbnails clearfix">
3939
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
40-
<a class="project-thumb" href="<?php the_permalink(); ?>" data-album-id="<?php echo $post->post_name; ?>">
41-
<div class="project-thumb-inside">
42-
<?php
43-
if ( has_post_thumbnail($post->ID) ) {
44-
the_post_thumbnail( 'gallery-thumb' );
45-
} else {
46-
$post_meta = get_post_custom();
47-
$post_meta = unserialize( $post_meta['dsframework-gallery'][0] );
48-
if( isset( $post_meta['attachment_urls'] ) ) {
49-
$image_urls = $post_meta['attachment_ids'];
50-
echo wp_get_attachment_image( $image_urls[0], 'gallery-thumb' );
51-
} else {
52-
echo '<div style="width: 360px; height: 250px; background: grey;">' . __('Album images not found.', 'dsframework') . '</div>';
53-
}
54-
}
55-
?>
56-
<h4 class="project-title"><?php the_title(); ?></h4>
57-
<p class="project-description"><?php echo get_the_excerpt(); ?></p>
58-
</div>
59-
</a>
40+
<?php get_template_part( 'content', 'masonry' ); ?>
6041
<?php endwhile; ?>
6142
</section>
6243
<?php wp_reset_postdata(); ?>
44+
<?php get_template_part( 'content', 'page-masonry' ); ?>
6345
</div>
6446
</div>
6547
<?php get_sidebar(); ?>

functions.php

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,4 +289,147 @@ function dsframework_add_admin_scripts( $hook ) {
289289
}
290290
add_action( 'admin_enqueue_scripts', 'dsframework_add_admin_scripts', 10, 1 );
291291

292+
/**
293+
* Retrieve list of galleryCategory objects.
294+
*
295+
* If you change the type to 'link' in the arguments, then the link categories
296+
* will be returned instead. Also all categories will be updated to be backwards
297+
* compatible with pre-2.3 plugins and themes.
298+
*
299+
* @since 2.1.0
300+
* @see get_terms() Type of arguments that can be changed.
301+
* @link http://codex.wordpress.org/Function_Reference/get_categories
302+
*
303+
* @param string|array $args Optional. Change the defaults retrieving categories.
304+
* @return array List of categories.
305+
*/
306+
function get_gallery_categories( $args = '' ) {
307+
$defaults = array( 'taxonomy' => 'ds-gallery-category' );
308+
$args = wp_parse_args( $args, $defaults );
309+
310+
$taxonomy = $args['taxonomy'];
311+
/**
312+
* Filter the taxonomy used to retrieve terms when calling get_gallery_categories().
313+
*
314+
* @since 2.7.0
315+
*
316+
* @param string $taxonomy Taxonomy to retrieve terms from.
317+
* @param array $args An array of arguments. @see get_terms()
318+
*/
319+
$taxonomy = apply_filters( 'get_gallery_categories_taxonomy', $taxonomy, $args );
320+
321+
// Back compat
322+
if ( isset($args['type']) && 'link' == $args['type'] ) {
323+
_deprecated_argument( __FUNCTION__, '3.0', '' );
324+
$taxonomy = $args['taxonomy'] = 'link_gallery_category';
325+
}
326+
327+
$categories = (array) get_terms( $taxonomy, $args );
328+
329+
foreach ( array_keys( $categories ) as $k )
330+
_make_cat_compat( $categories[$k] );
331+
332+
return $categories;
333+
}
334+
335+
/**
336+
* Retrieves galleryCategory data given a galleryCategory ID or galleryCategory object.
337+
*
338+
* If you pass the $galleryCategory parameter an object, which is assumed to be the
339+
* galleryCategory row object retrieved the database. It will cache the galleryCategory data.
340+
*
341+
* If you pass $galleryCategory an integer of the galleryCategory ID, then that galleryCategory will
342+
* be retrieved from the database, if it isn't already cached, and pass it back.
343+
*
344+
* If you look at get_term(), then both types will be passed through several
345+
* filters and finally sanitized based on the $filter parameter value.
346+
*
347+
* The galleryCategory will converted to maintain backwards compatibility.
348+
*
349+
* @since 1.5.1
350+
* @uses get_term() Used to get the galleryCategory data from the taxonomy.
351+
*
352+
* @param int|object $galleryCategory Category ID or Category row object
353+
* @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
354+
* @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
355+
* @return mixed Category data in type defined by $output parameter.
356+
*/
357+
function get_gallery_category( $galleryCategory, $output = OBJECT, $filter = 'raw' ) {
358+
$galleryCategory = get_term( $galleryCategory, 'ds-gallery-category', $output, $filter );
359+
if ( is_wp_error( $galleryCategory ) )
360+
return $galleryCategory;
361+
362+
_make_cat_compat( $galleryCategory );
363+
364+
return $galleryCategory;
365+
}
366+
367+
/**
368+
* Retrieve galleryCategory object by galleryCategory slug.
369+
*
370+
* @since 2.3.0
371+
*
372+
* @param string $slug The galleryCategory slug.
373+
* @return object GalleryCategory data object
374+
*/
375+
function get_gallery_category_by_slug( $slug ) {
376+
$category = get_term_by( 'slug', $slug, 'ds-gallery-category' );
377+
if ( $category )
378+
_make_cat_compat( $category );
379+
380+
return $category;
381+
}
382+
383+
/**
384+
* Retrieve galleryCategory link URL.
385+
*
386+
* @since 1.0.0
387+
* @see get_term_link()
388+
*
389+
* @param int|object $galleryCategory GalleryCategory ID or object.
390+
* @return string Link on success, empty string if galleryCategory does not exist.
391+
*/
392+
function get_gallery_category_link( $galleryCategory ) {
393+
if ( ! is_object( $galleryCategory ) )
394+
$galleryCategory = (int) $galleryCategory;
395+
396+
$galleryCategory = get_term_link( $galleryCategory, 'ds-gallery-category' );
397+
398+
if ( is_wp_error( $galleryCategory ) )
399+
return '';
400+
401+
return $galleryCategory;
402+
}
403+
404+
/**
405+
* Retrieves post in subcategory of galleryCategory object.
406+
*
407+
* @uses WP_Query() Used to get the post data from the galleryCategory.
408+
*
409+
* @param object $galleryCategory Category row object
410+
* @param boolean $includeChildren true for include children
411+
* @return array List of post.
412+
*/
413+
function post_in_gallery_category( $galleryCategory, $includeChildren = false ) {
414+
if(!isset($galleryCategory)) return array();
415+
416+
$tax_query = array(
417+
'relation' => 'AND',
418+
array(
419+
'taxonomy' => 'ds-gallery-category',
420+
'field' => 'slug',
421+
'terms' => $galleryCategory->slug,
422+
'include_children' => $includeChildren,
423+
'operator' => 'IN'
424+
)
425+
);
426+
$postLoop = new WP_Query( array(
427+
'post_type' => 'ds-gallery',
428+
'posts_per_page' => -1,
429+
'tax_query' => $tax_query
430+
));
431+
432+
return $postLoop;
433+
}
434+
292435
?>

0 commit comments

Comments
 (0)