relevant-resources
Signed-off-by: Jeff <jeff@gotenzing.com>
Showing
10 changed files
with
114 additions
and
2 deletions
| 1 | <?php | ||
| 2 | |||
| 3 | /** | ||
| 4 | * Relevant Resources Block Template. | ||
| 5 | * | ||
| 6 | * @param array $block The block settings and attributes. | ||
| 7 | * @param string $content The block inner HTML (empty). | ||
| 8 | * @param bool $is_preview True during AJAX preview. | ||
| 9 | * @param (int|string) $post_id The post ID this block is saved to. | ||
| 10 | */ | ||
| 11 | |||
| 12 | // Create id attribute allowing for custom "anchor" value. | ||
| 13 | $id = 'relevant-resources-' . $block['id']; | ||
| 14 | if( !empty($block['anchor']) ) { | ||
| 15 | $id = $block['anchor']; | ||
| 16 | } | ||
| 17 | |||
| 18 | // Create class attribute allowing for custom "className" and "align" values. | ||
| 19 | $className = 'relevant-resources'; | ||
| 20 | |||
| 21 | |||
| 22 | if( !empty($block['className']) ) { | ||
| 23 | $className .= ' ' . $block['className']; | ||
| 24 | } | ||
| 25 | if( !empty($block['align']) ) { | ||
| 26 | $className .= ' align' . $block['align']; | ||
| 27 | } | ||
| 28 | if( $is_preview ) { | ||
| 29 | $className .= ' is-admin'; | ||
| 30 | } | ||
| 31 | $categoryID = get_field( "categories" ); | ||
| 32 | $title = get_field( "title" ); | ||
| 33 | |||
| 34 | ?> | ||
| 35 | <div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?> "> | ||
| 36 | <h2><?php echo $title; ?></h2> | ||
| 37 | <?php $args = array( | ||
| 38 | 'post_type' => 'attachment', | ||
| 39 | 'posts_per_page' => -1, | ||
| 40 | 'tax_query' => array( | ||
| 41 | array( | ||
| 42 | 'taxonomy' => 'categories', | ||
| 43 | 'terms' => $categoryID, // term id | ||
| 44 | 'field' => 'term_id', | ||
| 45 | ) | ||
| 46 | ) | ||
| 47 | |||
| 48 | ); | ||
| 49 | if($categoryID == ""){ | ||
| 50 | $args = array( | ||
| 51 | 'post_type' => 'attachment', | ||
| 52 | 'posts_per_page' => -1, | ||
| 53 | ); | ||
| 54 | } | ||
| 55 | |||
| 56 | $attachments = get_posts($args); | ||
| 57 | |||
| 58 | $args = array( | ||
| 59 | 'post_type' => 'documents', | ||
| 60 | 'posts_per_page' => -1, | ||
| 61 | 'tax_query' => array( | ||
| 62 | array( | ||
| 63 | 'taxonomy' => 'categories', | ||
| 64 | 'terms' => $categoryID, // term id | ||
| 65 | 'field' => 'term_id', | ||
| 66 | ) | ||
| 67 | ) | ||
| 68 | ); | ||
| 69 | if($categoryID == ""){ | ||
| 70 | $args = array( | ||
| 71 | 'post_type' => 'documents', | ||
| 72 | 'posts_per_page' => -1, | ||
| 73 | ); | ||
| 74 | } | ||
| 75 | |||
| 76 | $documents = get_posts($args); | ||
| 77 | $posts = array_merge($documents, $attachments); | ||
| 78 | echo '<ul>'; | ||
| 79 | foreach($posts as $post ) { | ||
| 80 | $post_type = get_post_type( $post->ID ); | ||
| 81 | $link = wp_get_attachment_url( $post->ID ); | ||
| 82 | $description = get_post_meta($post->ID, 'description', true ); | ||
| 83 | $terms = wp_get_post_terms( $post->ID, 'document-format'); | ||
| 84 | if ( !empty( $terms ) && !is_wp_error( $terms ) ){ | ||
| 85 | |||
| 86 | foreach ( $terms as $term ) { | ||
| 87 | $term_list = $term->name; | ||
| 88 | |||
| 89 | } | ||
| 90 | |||
| 91 | } | ||
| 92 | if($post_type == 'documents'){ $link = get_post_meta($post->ID, 'document_link', true );}; | ||
| 93 | echo '<li><a class="'.$term_list.'" href="'.$link.'">'.$post->post_title.'</a><p>'.$description.'</p></li>'; | ||
| 94 | |||
| 95 | }; | ||
| 96 | echo '</ul>'; | ||
| 97 | ?> | ||
| 98 | </div> | ||
| 99 |
This diff is collapsed.
Click to expand it.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
| ... | @@ -66,5 +66,16 @@ if( function_exists('acf_add_options_page') ) { | ... | @@ -66,5 +66,16 @@ if( function_exists('acf_add_options_page') ) { |
| 66 | 'customClassName' => true | 66 | 'customClassName' => true |
| 67 | ] | 67 | ] |
| 68 | )); | 68 | )); |
| 69 | acf_register_block_type( array( | ||
| 70 | 'title' => __( 'Relevant Resources', 'client_textdomain' ), | ||
| 71 | 'name' => 'relevant-resources', | ||
| 72 | 'render_template' => 'blocks/relevant-resources/relevant-resources.php', | ||
| 73 | 'mode' => 'edit', | ||
| 74 | 'supports' => [ | ||
| 75 | 'align' => false, | ||
| 76 | 'anchor' => true, | ||
| 77 | 'customClassName' => true | ||
| 78 | ] | ||
| 79 | )); | ||
| 69 | 80 | ||
| 70 | } | 81 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
| ... | @@ -40,3 +40,4 @@ function wptp_add_tags_to_attachments() { | ... | @@ -40,3 +40,4 @@ function wptp_add_tags_to_attachments() { |
| 40 | register_taxonomy_for_object_type( 'post_tag', 'attachment' ); | 40 | register_taxonomy_for_object_type( 'post_tag', 'attachment' ); |
| 41 | } | 41 | } |
| 42 | add_action( 'init' , 'wptp_add_tags_to_attachments' ); | 42 | add_action( 'init' , 'wptp_add_tags_to_attachments' ); |
| 43 | ... | ... |
| ... | @@ -20,4 +20,5 @@ body{ | ... | @@ -20,4 +20,5 @@ body{ |
| 20 | @import "project_lead"; | 20 | @import "project_lead"; |
| 21 | @import "carousel"; | 21 | @import "carousel"; |
| 22 | @import "pojo_a11"; | 22 | @import "pojo_a11"; |
| 23 | @import "text_size_increased"; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 23 | @import "text_size_increased"; | ||
| 24 | @import "relevant_resources"; | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
This diff is collapsed.
Click to expand it.
-
Please register or sign in to post a comment