| @@ -24,9 +24,15 @@ | ||
| 24 | 24 | 'wpupg_order_by', |
| 25 | 25 | 'wpupg_order', |
| 26 | 26 | 'wpupg_order_custom_key', |
| 27 | 27 | 'wpupg_order_custom_key_numeric', |
| 28 | + 'wpupg_taxonomies', | |
| 28 | 29 | 'wpupg_template', |
| 30 | + 'wpupg_terms_hide_empty', | |
| 31 | + 'wpupg_terms_images_only', | |
| 32 | + 'wpupg_terms_order_by', | |
| 33 | + 'wpupg_terms_order', | |
| 34 | + 'wpupg_type', | |
| 29 | 35 | ); |
| 30 | 36 | |
| 31 | 37 | // Pagination fields with defaults |
| 32 | 38 | private $pagination_fields = array( |
| @@ -175,8 +181,14 @@ | ||
| 175 | 181 | |
| 176 | 182 | return $filter_style; |
| 177 | 183 | } |
| 178 | 184 | |
| 185 | + public function filter_dropdown_labels() | |
| 186 | + { | |
| 187 | + $dropdown_labels = maybe_unserialize( $this->meta( 'wpupg_filter_dropdown_labels' ) ); | |
| 188 | + return is_array( $dropdown_labels ) ? $dropdown_labels : array(); | |
| 189 | + } | |
| 190 | + | |
| 179 | 191 | public function filter_inverse() |
| 180 | 192 | { |
| 181 | 193 | return $this->meta( 'wpupg_filter_inverse' ); |
| 182 | 194 | } |
| @@ -341,8 +353,14 @@ | ||
| 341 | 353 | { |
| 342 | 354 | return $this->post->post_name; |
| 343 | 355 | } |
| 344 | 356 | |
| 357 | + public function taxonomies() | |
| 358 | + { | |
| 359 | + $taxonomies = maybe_unserialize( $this->meta( 'wpupg_taxonomies' ) ); | |
| 360 | + return is_array( $taxonomies ) ? $taxonomies : array(); | |
| 361 | + } | |
| 362 | + | |
| 345 | 363 | public function template() |
| 346 | 364 | { |
| 347 | 365 | return WPUltimatePostGrid::addon( 'custom-templates' )->get_template( $this->template_id() ); |
| 348 | 366 | } |
| @@ -351,13 +369,39 @@ | ||
| 351 | 369 | { |
| 352 | 370 | return $this->meta( 'wpupg_template' ); |
| 353 | 371 | } |
| 354 | 372 | |
| 373 | + public function terms_hide_empty() | |
| 374 | + { | |
| 375 | + return $this->meta( 'wpupg_terms_hide_empty' ); | |
| 376 | + } | |
| 377 | + | |
| 378 | + public function terms_images_only() | |
| 379 | + { | |
| 380 | + return $this->meta( 'wpupg_terms_images_only' ); | |
| 381 | + } | |
| 382 | + | |
| 383 | + public function terms_order() | |
| 384 | + { | |
| 385 | + return $this->meta( 'wpupg_terms_order' ); | |
| 386 | + } | |
| 387 | + | |
| 388 | + public function terms_order_by() | |
| 389 | + { | |
| 390 | + return $this->meta( 'wpupg_terms_order_by' ); | |
| 391 | + } | |
| 392 | + | |
| 355 | 393 | public function title() |
| 356 | 394 | { |
| 357 | 395 | return $this->post->post_title; |
| 358 | 396 | } |
| 359 | 397 | |
| 398 | + public function type() | |
| 399 | + { | |
| 400 | + $type = $this->meta( 'wpupg_type' ); | |
| 401 | + return $type ? $type : 'posts'; | |
| 402 | + } | |
| 403 | + | |
| 360 | 404 | /** |
| 361 | 405 | * Helper functions |
| 362 | 406 | */ |
| 363 | 407 | |
| @@ -428,8 +472,13 @@ | ||
| 428 | 472 | } |
| 429 | 473 | |
| 430 | 474 | public function draw_posts( $page = 0, $post_ids = null ) |
| 431 | 475 | { |
| 476 | + if( $this->type() == 'terms' ) { | |
| 477 | + return $this->draw_terms(); | |
| 478 | + } | |
| 479 | + | |
| 480 | + // Draw Posts | |
| 432 | 481 | $output = ''; |
| 433 | 482 | $grid_posts = $this->posts(); |
| 434 | 483 | $posts = $this->get_posts( $page, $post_ids ); |
| 435 | 484 | |
| @@ -449,8 +498,71 @@ | ||
| 449 | 498 | $classes[] = 'wpupg-tax-' . $taxonomy . '-' . $term; |
| 450 | 499 | } |
| 451 | 500 | } |
| 452 | 501 | } |
| 502 | + | |
| 503 | + $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this ); | |
| 504 | + $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this ); | |
| 505 | + $post = apply_filters( 'wpupg_output_grid_post', $post, $this ); | |
| 506 | + | |
| 507 | + $output .= apply_filters( 'wpupg_output_grid_html', $template->output_string( $post, $classes ), $template, $post, $classes ); | |
| 508 | + } | |
| 509 | + | |
| 510 | + return $output; | |
| 511 | + } | |
| 512 | + | |
| 513 | + public function draw_terms() | |
| 514 | + { | |
| 515 | + $output = ''; | |
| 516 | + | |
| 517 | + $args = array( | |
| 518 | + 'orderby' => $this->terms_order_by(), | |
| 519 | + 'order' => $this->terms_order(), | |
| 520 | + 'hide_empty' => $this->terms_hide_empty(), | |
| 521 | + ); | |
| 522 | + | |
| 523 | + if( $this->terms_images_only() ) { | |
| 524 | + $args['meta_query'] = array( | |
| 525 | + array( | |
| 526 | + 'key' => 'wpupg_custom_image', | |
| 527 | + 'compare' => '!=', | |
| 528 | + 'value' => '', | |
| 529 | + ) | |
| 530 | + ); | |
| 531 | + } | |
| 532 | + | |
| 533 | + $terms = get_terms( $this->taxonomies(), $args ); | |
| 534 | + | |
| 535 | + foreach( $terms as $term ) { | |
| 536 | + // Emulate post object | |
| 537 | + $post = (object) array( | |
| 538 | + 'term' => true, | |
| 539 | + 'ID' => $term->term_id, | |
| 540 | + 'post_author' => '', | |
| 541 | + 'post_name' => $term->slug, | |
| 542 | + 'post_type' => $term->taxonomy, | |
| 543 | + 'post_title' => $term->name, | |
| 544 | + 'post_date' => '0000-00-00 00:00:00', | |
| 545 | + 'post_date_gmt' => '0000-00-00 00:00:00', | |
| 546 | + 'post_content' => $term->description, | |
| 547 | + 'post_excerpt' => $term->description, | |
| 548 | + 'post_status' => 'publish', | |
| 549 | + 'comment_status' => 'open', | |
| 550 | + 'ping_status' => 'open', | |
| 551 | + 'post_password' => '', | |
| 552 | + 'post_parent' => $term->parent, | |
| 553 | + 'post_modified' => '0000-00-00 00:00:00', | |
| 554 | + 'post_modified_gmt' => '0000-00-00 00:00:00', | |
| 555 | + 'comment_count' => '0', | |
| 556 | + 'menu_order' => '0', | |
| 557 | + ); | |
| 558 | + | |
| 559 | + $classes = array( | |
| 560 | + 'wpupg-item', | |
| 561 | + 'wpupg-page-0', | |
| 562 | + 'wpupg-post-' . $post->ID, | |
| 563 | + 'wpupg-type-' . $post->post_type, | |
| 564 | + ); | |
| 453 | 565 | |
| 454 | 566 | $classes = apply_filters( 'wpupg_output_grid_classes', $classes, $this ); |
| 455 | 567 | $template = apply_filters( 'wpupg_output_grid_template', $this->template(), $this ); |
| 456 | 568 | $post = apply_filters( 'wpupg_output_grid_post', $post, $this ); |