63de5caa by Jeff Balicki

relevant-resources

Signed-off-by: Jeff <jeff@gotenzing.com>
1 parent 9b37e185
<?php
/**
* Relevant Resources Block Template.
*
* @param array $block The block settings and attributes.
* @param string $content The block inner HTML (empty).
* @param bool $is_preview True during AJAX preview.
* @param (int|string) $post_id The post ID this block is saved to.
*/
// Create id attribute allowing for custom "anchor" value.
$id = 'relevant-resources-' . $block['id'];
if( !empty($block['anchor']) ) {
$id = $block['anchor'];
}
// Create class attribute allowing for custom "className" and "align" values.
$className = 'relevant-resources';
if( !empty($block['className']) ) {
$className .= ' ' . $block['className'];
}
if( !empty($block['align']) ) {
$className .= ' align' . $block['align'];
}
if( $is_preview ) {
$className .= ' is-admin';
}
$categoryID = get_field( "categories" );
$title = get_field( "title" );
?>
<div id="<?php echo esc_attr($id); ?>" class="<?php echo esc_attr($className); ?> ">
<h2><?php echo $title; ?></h2>
<?php $args = array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'categories',
'terms' => $categoryID, // term id
'field' => 'term_id',
)
)
);
if($categoryID == ""){
$args = array(
'post_type' => 'attachment',
'posts_per_page' => -1,
);
}
$attachments = get_posts($args);
$args = array(
'post_type' => 'documents',
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'categories',
'terms' => $categoryID, // term id
'field' => 'term_id',
)
)
);
if($categoryID == ""){
$args = array(
'post_type' => 'documents',
'posts_per_page' => -1,
);
}
$documents = get_posts($args);
$posts = array_merge($documents, $attachments);
echo '<ul>';
foreach($posts as $post ) {
$post_type = get_post_type( $post->ID );
$link = wp_get_attachment_url( $post->ID );
$description = get_post_meta($post->ID, 'description', true );
$terms = wp_get_post_terms( $post->ID, 'document-format');
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach ( $terms as $term ) {
$term_list = $term->name;
}
}
if($post_type == 'documents'){ $link = get_post_meta($post->ID, 'document_link', true );};
echo '<li><a class="'.$term_list.'" href="'.$link.'">'.$post->post_title.'</a><p>'.$description.'</p></li>';
};
echo '</ul>';
?>
</div>
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') ) {
'customClassName' => true
]
));
acf_register_block_type( array(
'title' => __( 'Relevant Resources', 'client_textdomain' ),
'name' => 'relevant-resources',
'render_template' => 'blocks/relevant-resources/relevant-resources.php',
'mode' => 'edit',
'supports' => [
'align' => false,
'anchor' => true,
'customClassName' => true
]
));
}
\ No newline at end of file
......
......@@ -40,3 +40,4 @@ function wptp_add_tags_to_attachments() {
register_taxonomy_for_object_type( 'post_tag', 'attachment' );
}
add_action( 'init' , 'wptp_add_tags_to_attachments' );
......
......@@ -20,4 +20,5 @@ body{
@import "project_lead";
@import "carousel";
@import "pojo_a11";
@import "text_size_increased";
\ No newline at end of file
@import "text_size_increased";
@import "relevant_resources";
\ No newline at end of file
......
......@@ -2,5 +2,5 @@
Theme Name: MSF CA Child
Author: Tenzing Communications
Template: msf-ca
Version: 1.0.427
Version: 1.0.428
*/
......