Adds basic templates for Tainacan Single Item page. Begins experiments with attachments and post navigation.

This commit is contained in:
mateuswetah 2020-09-08 23:07:50 -03:00
parent af37900bf4
commit 3c81d206ce
7 changed files with 426 additions and 142 deletions

View File

@ -5,3 +5,133 @@ if (! defined('WP_DEBUG')) {
add_action( 'wp_enqueue_scripts', function () {
wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
});
/**
* Filters the content if we're in a single item page.
*/
function blocksy_tainacan_filter_the_content_in_the_main_loop( $content ) {
if ( is_singular() && in_the_loop() && is_main_query() && function_exists('tainacan_get_item') && tainacan_get_item(get_the_ID()) != null ) {
return get_template_part( 'template-parts/single-items-page' );
}
return $content;
}
add_filter( 'the_content', 'blocksy_tainacan_filter_the_content_in_the_main_loop', 10, 1 );
/**
* Retrieves an item adjacent link, either using WP strategy or Tainacan plugin tainacan_get_adjacent_items()
*/
function blocksy_tainacan_get_adjacent_item_links() {
$has_thumb = get_theme_mod($prefix . '_has_post_nav_thumb', 'yes') === 'yes';
if (function_exists('tainacan_get_adjacent_items') && isset($_GET['pos'])) {
$adjacent_items = tainacan_get_adjacent_items();
if (isset($adjacent_items['next'])) {
$next_link_url = $adjacent_items['next']['url'];
$next_title = $adjacent_items['next']['title'];
} else {
$next_link_url = false;
}
if (isset($adjacent_items['previous'])) {
$previous_link_url = $adjacent_items['previous']['url'];
$previous_title = $adjacent_items['previous']['title'];
} else {
$previous_link_url = false;
}
} else {
//Get the links to the Previous and Next Post
$previous_link_url = get_permalink( get_previous_post() );
$next_link_url = get_permalink( get_next_post() );
//Get the title of the previous post and next post
$previous_title = get_the_title( get_previous_post() );
$next_title = get_the_title( get_next_post() );
}
$previous = '';
$next = '';
if ($has_thumb) {
if (function_exists('tainacan_get_adjacent_items') && isset($_GET['pos'])) {
if ($adjacent_items['next']) {
$next_thumb = $adjacent_items['next']['thumbnail']['tainacan-medium'][0];
}
if ($adjacent_items['previous']) {
$previous_thumb = $adjacent_items['previous']['thumbnail']['tainacan-medium'][0];
}
} else {
//Get the thumnail url of the previous and next post
$previous_thumb = get_the_post_thumbnail_url( get_previous_post(), 'tainacan-medium' );
$next_thumb = get_the_post_thumbnail_url( get_next_post(), 'tainacan-medium' );
}
$previous_post_image_output = blocksy_simple_image(
$previous_thumb,
[
'inner_content' => '<svg width="20px" height="15px" viewBox="0 0 20 15"><polygon points="0,7.5 5.5,13 6.4,12.1 2.4,8.1 20,8.1 20,6.9 2.4,6.9 6.4,2.9 5.5,2 "/></svg>',
'ratio' => '1/1',
'tag_name' => 'figure'
]
);
$next_post_image_output = blocksy_simple_image(
$next_thumb,
[
'inner_content' => '<svg width="20px" height="15px" viewBox="0 0 20 15"><polygon points="14.5,2 13.6,2.9 17.6,6.9 0,6.9 0,8.1 17.6,8.1 13.6,12.1 14.5,13 20,7.5 "/></svg>',
'ratio' => '1/1',
'tag_name' => 'figure'
]
);
} else {
$previous = $previous_link_url === false ? '' : '<a rel="prev" href="' . $previous_link_url . '"><i class="tainacan-icon tainacan-icon-arrowleft tainacan-icon-30px"></i>&nbsp; <span>' . $previous_title . '</span></a>';
$next = $next_link_url === false ? '' :'<a rel="next" href="' . $next_link_url . '"><span>' . $next_title . '</span> &nbsp;<i class="tainacan-icon tainacan-icon-arrowright tainacan-icon-30px"></i></a>';
}
// Creates the links
$previous = $previous_link_url === false ? '' : (
'<a href="' . $previous_link_url .'" rel="prev" class="nav-item-prev"> ' .
($has_thumb ? $previous_post_image_output : '') .
'<div class="item-content">' .
'<span class="item-label">' . __( 'Previous item', 'blocksy-tainacan' ) . '</span>' .
(!empty( $previous_title ) ? ('<span class="item-title">' . $previous_title . '</span>') : '') .
'</div>'.
'</a>');
$next = $next_link_url === false ? '' : (
'<a href="' . $next_link_url .'" rel="prev" class="nav-item-next"> ' .
'<div class="item-content">' .
(!empty( $next_title ) ? ('<span class="item-title">' . $next_title . '</span>') : '') .
'<span class="item-label">' . __( 'Next item', 'blocksy-tainacan') . '</span>' .
'</div>' .
($has_thumb ? $next_post_image_output : '') .
'</a>');
return ['next' => $next, 'previous' => $previous];
}
/**
* Retrieves the current items list source link
*/
function blocksy_tainacan_get_source_item_list_url() {
$args = $_GET;
if (isset($args['ref'])) {
$ref = $_GET['ref'];
unset($args['pos']);
unset($args['ref']);
unset($args['source_list']);
return $ref . '?' . http_build_query(array_merge($args));
} else {
unset($args['pos']);
unset($args['ref']);
unset($args['source_list']);
return tainacan_the_collection_url() . '?' . http_build_query(array_merge($args));
}
}

View File

@ -1,142 +1 @@
<?php get_header(); ?>
<div class="wrap">
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php if ( have_posts() ) : ?>
<article role="article" id="post_<?php the_ID()?>" class="page type-page hentry singular">
<?php do_action( 'docksy-tainacan-single-item-top' ); ?>
<?php while ( have_posts() ) : the_post(); ?>
<header class="entry-header has-text-align-center">
<div class="entry-categories">
<div class="entry-categories-inner">
<?php if ( function_exists('tainacan_the_collection_url') ): ?>
<a href="<?php tainacan_the_collection_url(); ?>">
<?php tainacan_the_collection_name(); ?>
</a>
<?php else : ?>
<span><?php tainacan_the_collection_name(); ?></span>
<?php endif; ?>
</div>
</div>
<h1 class="entry-title">
<?php the_title(); ?>
</h1>
</header>
<?php do_action( 'docksy-tainacan-single-item-after-title' ); ?>
<section class="tainacan-entry-content entry-content">
<h2 class="title-content-items">Informações</h2>
<div class="single-item-collection--information justify-content-center">
<div class="tainacan-metadata-list">
<?php do_action( 'docksy-tainacan-single-item-metadata-begin' ); ?>
<?php
$args = array(
'before_title' => '<div><h3>',
'after_title' => '</h3>',
'before_value' => '<p>',
'after_value' => '</p></div>',
);
//$field = null;
tainacan_the_metadata( $args );
?>
<?php do_action( 'docksy-tainacan-single-item-metadata-end' ); ?>
</div>
</div>
</section>
<?php do_action( 'docksy-tainacan-single-item-after-metadata' ); ?>
<?php if ( tainacan_has_document() ) : ?>
<hr>
<section class="tainacan-entry-content entry-content">
<h2 class="title-content-items">Documento</h2>
<div class="single-item-collection--document">
<?php tainacan_the_document(); ?>
</div>
</section>
<?php endif; ?>
<?php do_action( 'docksy-tainacan-single-item-after-document' ); ?>
<?php
if (function_exists('tainacan_get_the_attachments')) {
$attachments = tainacan_get_the_attachments();
} else {
// compatibility with pre 0.11 tainacan plugin
$attachments = array_values(
get_children(
array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'numberposts' => -1,
)
)
);
}
?>
<?php if ( ! empty( $attachments ) ) : ?>
<hr>
<section class="tainacan-entry-content entry-content">
<h2 class="title-content-items">Anexos</h2>
<div class="single-item-collection--attachments">
<?php foreach ( $attachments as $attachment ) { ?>
<?php
if ( function_exists('tainacan_get_attachment_html_url') ) {
$href = tainacan_get_attachment_html_url($attachment->ID);
} else {
$href = wp_get_attachment_url($attachment->ID, 'large');
}
?>
<div class="single-item-collection--attachments-file">
<a
class="<?php if (!wp_get_attachment_image( $attachment->ID, 'docksy-tainacan-item-attachments')) echo'attachment-without-image'; ?>"
href="<?php echo $href; ?>" data-toggle="lightbox" data-gallery="example-gallery">
<?php
echo wp_get_attachment_image( $attachment->ID, 'docksy-tainacan-item-attachments', true );
echo get_the_title( $attachment->ID );
?>
</a>
</div>
<?php }
?>
</div>
</section>
<footer class="entry-footer">
<?php
if ( comments_open() || get_comments_number() ) :
comments_template();
endif; ?>
</footer>
</article>
<?php endif; ?>
<?php do_action( 'docksy-tainacan-single-item-after-attachments' ); ?>
<?php endwhile; ?>
<?php do_action( 'docksy-tainacan-single-item-bottom' ); ?>
<?php else : ?>
Nada encontrado aqui.
<?php endif; ?>
</main>
</div>
</div>
<?php get_footer(); ?>
<?php get_template_part('single'); ?>

View File

@ -0,0 +1,134 @@
<?php
if (function_exists('tainacan_get_the_attachments')) {
$attachments = tainacan_get_the_attachments();
} else {
// compatibility with pre 0.11 tainacan plugin
$attachments = array_values(
get_children(
array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'order' => 'ASC',
'numberposts' => -1,
)
)
);
}
function get_attachment_id($attachment) {
return $attachment->ID;
}
?>
<?php if ( !empty( $attachments ) || ( get_theme_mod( 'tainacan_single_item_gallery_mode', false) && tainacan_has_document() )) : ?>
<div>
<?php if ( !get_theme_mod( 'tainacan_single_item_gallery_mode', false ) && get_theme_mod('tainacan_single_item_attachments_section_label', __( 'Attachments', 'blocksy-tainacan' )) != '') : ?>
<h2 class="title-content-items" id="single-item-attachments-label">
<?php echo esc_html( get_theme_mod('tainacan_single_item_attachments_section_label', __( 'Attachments', 'blocksy-tainacan' )) ); ?>
</h2>
<?php endif; ?>
<?php if ( get_theme_mod( 'tainacan_single_item_gallery_mode', false ) && get_theme_mod('tainacan_single_item_documents_section_label', __( 'Documents', 'blocksy-tainacan' )) != '') : ?>
<h2 class="title-content-items" id="single-item-documents-label">
<?php echo esc_html( get_theme_mod('tainacan_single_item_documents_section_label', __( 'Documents', 'blocksy-tainacan' )) ); ?>
</h2>
<?php endif; ?>
<section class="tainacan-content single-item-collection margin-two-column">
<?php if (get_theme_mod( 'tainacan_single_item_gallery_mode', false )): ?>
<div class="single-item-collection--gallery">
<?php if ( tainacan_has_document() ) : ?>
<section class="tainacan-content single-item-collection margin-two-column">
<div class="single-item-collection--document">
<?php
tainacan_the_document();
if ( !get_theme_mod( 'tainacan_single_item_hide_download_document', false ) && function_exists('tainacan_the_item_document_download_link') && tainacan_the_item_document_download_link() != '' ) {
echo '<span class="tainacan-item-file-download">' . tainacan_the_item_document_download_link() . '</span>';
}
?>
</div>
</section>
<?php endif; ?>
<?php foreach ( $attachments as $attachment ) { ?>
<section class="tainacan-content single-item-collection margin-two-column">
<div class="single-item-collection--document">
<?php
if ( function_exists('tainacan_get_single_attachment_as_html') ) {
tainacan_get_single_attachment_as_html($attachment->ID);
}
if ( !get_theme_mod( 'tainacan_single_item_hide_download_document', false ) && function_exists('tainacan_the_item_attachment_download_link') && tainacan_the_item_attachment_download_link($attachment->ID) != '' ) {
echo '<span class="tainacan-item-file-download">' . tainacan_the_item_attachment_download_link($attachment->ID) . '</span>';
}
?>
</div>
</section>
<?php } ?>
</div>
<?php if ( (tainacan_has_document() && $attachments && sizeof($attachments) > 0 ) || (!tainacan_has_document() && $attachments && sizeof($attachments) > 1 ) ) : ?>
<div class="single-item-collection--gallery-items">
<?php if ( tainacan_has_document() ) : ?>
<div class="single-item-collection--attachments-file">
<?php
the_post_thumbnail('tainacan-medium-full', array('class' => 'item-card--thumbnail'));
echo '<br>';
?>
<span class="single-item-file-name <?php if (get_theme_mod('tainacan_single_item_hide_files_name', false)) echo 'sr-only' ?>"><?php echo __( 'Document', 'blocksy-tainacan' ); ?></span>
</div>
<?php endif; ?>
<?php foreach ( $attachments as $attachment ) { ?>
<div class="single-item-collection--attachments-file">
<div class="<?php if (!wp_get_attachment_image( $attachment->ID, 'blocksy-tainacan-item-attachments')) echo'attachment-without-image'; ?>">
<?php
echo wp_get_attachment_image( $attachment->ID, 'blocksy-tainacan-item-attachments', true );
echo '<br>';
?>
<span class="single-item-file-name <?php if (get_theme_mod('tainacan_single_item_hide_files_name', false)) echo 'sr-only' ?>"><?php echo get_the_title( $attachment->ID ); ?></span>
</div>
</div>
<?php } ?>
</div>
<?php endif; ?>
<?php else : ?>
<div class="single-item-collection--attachments">
<?php
echo blocksy_flexy([
'images' => array_map('get_attachment_id', $attachments),
'size' => 'full',
'pills_images' => array_map('get_attachment_id', $attachments),
'pills_count' => '6'
]);
?>
<?php /*
foreach ( $attachments as $attachment ) { ?>
<?php
if ( function_exists('tainacan_get_attachment_html_url') ) {
$href = tainacan_get_attachment_html_url($attachment->ID);
} else {
$href = wp_get_attachment_url($attachment->ID, 'large');
}
?>
<div class="single-item-collection--attachments-file">
<a
class="<?php if (!wp_get_attachment_image( $attachment->ID, 'blocksy-tainacan-item-attachments')) echo'attachment-without-image'; ?>"
href="<?php echo $href; ?>"
data-toggle="lightbox"
data-gallery="example-gallery">
<?php
echo wp_get_attachment_image( $attachment->ID, 'blocksy-tainacan-item-attachments', true );
echo '<br>';
?>
<span class="single-item-file-name <?php if (get_theme_mod('tainacan_single_item_hide_files_name', false)) echo 'sr-only' ?>"><?php echo get_the_title( $attachment->ID ); ?></span>
</a>
</div>
<?php }
*/
?>
</div>
<?php endif; ?>
</section>
</div>
<div class="my-5 border-bottom border-silver"></div>
<?php endif; ?>

View File

@ -0,0 +1,22 @@
<?php if ( tainacan_has_document() && !get_theme_mod( 'tainacan_single_item_gallery_mode', false )) : ?>
<div>
<?php if ( get_theme_mod('tainacan_single_item_document_section_label', __( 'Document', 'blocksy-tainacan' )) != '') : ?>
<h2 class="title-content-items" id="single-item-document-label">
<?php echo esc_html( get_theme_mod('tainacan_single_item_document_section_label', __( 'Document', 'blocksy-tainacan' )) ); ?>
</h2>
<?php endif; ?>
<section class="tainacan-content single-item-collection margin-two-column">
<div class="single-item-collection--document">
<?php
tainacan_the_document();
if ( !get_theme_mod( 'tainacan_single_item_hide_download_document', false ) && function_exists('tainacan_the_item_document_download_link') && tainacan_the_item_document_download_link() != '' ) {
echo '<span class="tainacan-item-file-download">' . tainacan_the_item_document_download_link() . '</span>';
}
?>
</div>
</section>
</div>
<div class="my-5 border-bottom border-silver"></div>
<?php endif; ?>

View File

@ -0,0 +1,39 @@
<div>
<?php if ( get_theme_mod('tainacan_single_item_metadata_section_label', '') != '') : ?>
<h2 class="title-content-items" id="single-item-metadata-label">
<?php echo esc_html( get_theme_mod('tainacan_single_item_metadata_section_label', '') ); ?>
</h2>
<?php endif; ?>
<section class="tainacan-content single-item-collection margin-two-column">
<div class="single-item-collection--information justify-content-center">
<div class="row">
<div class="col s-item-collection--metadata">
<?php if (has_post_thumbnail() && get_theme_mod( 'tainacan_single_item_display_thumbnail', true )): ?>
<div class="tainacan-item-thumbnail-container card">
<div class="card-body">
<h3><?php _e( 'Thumbnail', 'blocksy-tainacan' ); ?></h3>
<?php the_post_thumbnail('tainacan-medium-full', array('class' => 'item-card--thumbnail')); ?>
</div>
</div>
<?php endif; ?>
<?php do_action( 'blocksy-tainacan-single-item-metadata-begin' ); ?>
<?php
$args = array(
'before_title' => '<div><h3>',
'after_title' => '</h3>',
'before_value' => '<p>',
'after_value' => '</p></div>',
'exclude_title' => get_theme_mod('tainacan_single_item_hide_core_title_metadata', false)
);
//$field = null;
tainacan_the_metadata( $args );
?>
<?php do_action( 'blocksy-tainacan-single-item-metadata-end' ); ?>
</div>
</div>
</div>
</section>
</div>
<div class="my-5 border-bottom border-silver"></div>

View File

@ -0,0 +1,52 @@
<?php
$next = '';
$previous = '';
$prefix = blocksy_manager()->screen->get_prefix();
if (get_theme_mod( $prefix . '_has_post_nav', $prefix === 'single_blog_post' ? 'yes' : 'no' ) === 'yes') {
$container_class = 'post-navigation';
$container_class .= ' ' . blocksy_visibility_classes(get_theme_mod(
$prefix . '_post_nav_visibility',
[
'desktop' => true,
'tablet' => true,
'mobile' => true,
]
));
$has_thumb = get_theme_mod($prefix . '_has_post_nav_thumb', 'yes') === 'yes';
if ($has_thumb)
$container_class .= ' has-thumbnails';
$adjacent_links = [
'next' => '',
'previous' => ''
];
$adjacent_links = blocksy_tainacan_get_adjacent_item_links();
$previous = $adjacent_links['previous'];
$next = $adjacent_links['next'];
}
?>
<?php if ($previous !== '' || $next !== '') : ?>
<nav class="<?php echo esc_attr( $container_class ); ?>">
<?php if ( $previous !== '' ) {
echo $previous;
} else { ?>
<div class="nav-item-prev"></div>
<?php } ?>
<?php if ( $next !== '' ) {
echo $next;
} else { ?>
<div class="nav-item-next"></div>
<?php } ?>
</nav>
<?php endif; ?>

View File

@ -0,0 +1,48 @@
<?php do_action( 'blocksy-tainacan-single-item-top' ); ?>
<?php
do_action( 'blocksy-tainacan-single-item-after-title' );
echo '<div class="single-item-data-section">';
switch (get_theme_mod( 'tainacan_single_item_layout_sections_order', 'document-attachments-metadata')) {
case 'document-attachments-metadata':
get_template_part( 'template-parts/single-items-document' );
do_action( 'blocksy-tainacan-single-item-after-document' );
get_template_part( 'template-parts/single-items-attachments' );
do_action( 'blocksy-tainacan-single-item-after-attachments' );
get_template_part( 'template-parts/single-items-metadata' );
do_action( 'blocksy-tainacan-single-item-after-metadata' );
break;
case 'metadata-document-attachments':
get_template_part( 'template-parts/single-items-metadata' );
do_action( 'blocksy-tainacan-single-item-after-metadata' );
get_template_part( 'template-parts/single-items-document' );
do_action( 'blocksy-tainacan-single-item-after-document' );
get_template_part( 'template-parts/single-items-attachments' );
do_action( 'blocksy-tainacan-single-item-after-attachments' );
break;
case 'document-metadata-attachments':
get_template_part( 'template-parts/single-items-document' );
do_action( 'blocksy-tainacan-single-item-after-document' );
get_template_part( 'template-parts/single-items-metadata' );
do_action( 'blocksy-tainacan-single-item-after-metadata' );
get_template_part( 'template-parts/single-items-attachments' );
do_action( 'blocksy-tainacan-single-item-after-attachments' );
break;
}
echo '</div>';
?>
<?php get_template_part( 'template-parts/single-items-navigation' ); ?>
<?php do_action( 'blocksy-tainacan-single-item-bottom' ); ?>