Adds Taxononmy Single (Terms List) page.

This commit is contained in:
mateuswetah 2023-03-08 12:21:46 -03:00
parent e70bff9da1
commit c5e87a6e9e
15 changed files with 1800 additions and 15 deletions

View File

@ -18,9 +18,6 @@ if (! defined('WP_DEBUG') ) {
const TAINACAN_BLOCKSY_VERSION = '0.1.21';
const TAINACAN_BLOCKSY_IS_CHILD_THEME = false;
/* Disables Tainacan Theme Helper the_content filter, which is used to build a custom item template. */
define('TAINACAN_DISABLE_ITEM_THE_CONTENT_FILTER', true);
/* Tools to define our next constants */
require 'utils.php';
@ -44,6 +41,11 @@ if ( TAINACAN_BLOCKSY_IS_CHILD_THEME || ( TAINACAN_BLOCKSY_IS_BLOCKSY_ACTIVATED
/* Template redirection necessary only if in a plugin */
if ( !TAINACAN_BLOCKSY_IS_CHILD_THEME ) {
/* Disables Tainacan Theme Helper the_content filter, which is used to build a custom item and taxonomy (terms list) template. */
define('TAINACAN_DISABLE_ITEM_THE_CONTENT_FILTER', true);
define('TAINACAN_DISABLE_TAXONOMY_THE_CONTENT_FILTER', true);
require TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/plugin.php';
}

View File

@ -54,6 +54,28 @@ if ( !function_exists('tainacan_blocksy_custom_post_types_single_options') ) {
'is_general_cpt' => true
], false);
if ( is_array($item_extra_options) ) {
array_splice(
$options['options'][$post_type . '_single_section_options']['inner-options'][0],
1,
0,
$item_extra_options
);
}
} else if ( $post_type == 'tainacan-taxonomy' ) {
// Change the section title in the customizer
$options['title'] = sprintf(
$options['title'] . ' ' . __('(terms list)', 'tainacan-blocksy'),
$post_type_object->labels->name
);
// Extra options to the single taxonomy (terms list) template
$item_extra_options = blocksy_get_options(TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/posts/tainacan-taxonomy-single.php', [
'post_type' => $post_type_object,
'is_general_cpt' => true
], false);
if ( is_array($item_extra_options) ) {
array_splice(
$options['options'][$post_type . '_single_section_options']['inner-options'][0],
@ -149,13 +171,21 @@ if ( !function_exists('tainacan_blocksy_the_content_for_items') ) {
// This should only happen if we have Tainacan plugin installed
if ( defined ('TAINACAN_VERSION') ) {
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
if ( !is_single() || !is_singular() || !in_the_loop() || !is_main_query() )
return $content;
$post_type = get_post_type();
// Check if we're inside the main loop in a single Post.
if ( in_array($post_type, $collections_post_types) && is_singular() && in_the_loop() && is_main_query() ) {
// Checks if we're in the taxonomy single (aka, terms archive)
if ( $post_type == 'tainacan-taxonomy' )
return tainacan_blocksy_get_template_part( 'tainacan/archive-terms' );
// Checks if we're in the collection item single
$collections_post_types = \Tainacan\Repositories\Repository::get_collections_db_identifiers();
if ( in_array($post_type, $collections_post_types) )
return tainacan_blocksy_get_template_part( 'tainacan/item-single-page' );
}
}
return $content;

View File

@ -51,6 +51,13 @@ if ( TAINACAN_BLOCKSY_BLOCKSY_THEME_VERSION !== NULL && ( version_compare(TAINAC
'chunk' => 'global',
'forced_call' => true
], $args));
} else if ( $post_type == 'tainacan-taxonomy' ) {
blocksy_theme_get_dynamic_styles(array_merge([
'name' => 'global/posts-listing',
'chunk' => 'global',
'forced_call' => true,
'prefixes' => blocksy_manager()->screen->get_single_prefixes()
], $args));
}
}
}, 10, 3);

View File

@ -446,4 +446,229 @@ if ( !function_exists('tainacan_blocksy_custom_breadcrumbs') ) {
}
add_filter( 'blocksy:breadcrumbs:items-array', 'tainacan_blocksy_custom_breadcrumbs', 10, 3 );
/**
* Retrieves an item adjacent link, either using WP strategy or Tainacan plugin tainacan_get_adjacent_items()
*/
if ( !function_exists('blocksy_tainacan_the_taxonomies_pagination') ) {
function blocksy_tainacan_the_taxonomies_pagination($total_terms, $args = []) {
global $wp_query;
$allowed_prefixes_args = [
'allowed_prefixes' => [
'blog',
'woo_categories'
],
'default_prefix' => 'blog'
];
$args = wp_parse_args(
$args,
[
'query' => $wp_query,
'prefix' => blocksy_manager()->screen->get_prefix(
$allowed_prefixes_args
),
'has_pagination' => '__DEFAULT__',
'pagination_type' => '__DEFAULT__',
'last_page_text' => __('No more posts to load', 'blocksy'),
'total_pages' => null,
'current_page' => null,
'format' => null,
'base' => null
]
);
$args['prefix'] = blocksy_manager()->screen->process_allowed_prefixes(
$args['prefix'],
$allowed_prefixes_args
);
if ($args['has_pagination'] === '__DEFAULT__') {
$args['has_pagination'] = get_theme_mod(
$args['prefix'] . '_has_pagination',
'yes'
) === 'yes';
}
if ($args['pagination_type'] === '__DEFAULT__') {
$args['pagination_type'] = get_theme_mod(
$args['prefix'] . '_pagination_global_type',
'simple'
);
}
$button_output = '';
if (
$args['pagination_type'] === 'load_more'
&&
intval($args['current_page']) !== intval($args['total_pages'])
) {
$label_button = get_theme_mod(
$args['prefix'] . '_load_more_label',
__('Load More', 'blocksy')
);
$button_output = '<button class="ct-button ct-load-more">' . $label_button . '</button>';
}
if (
$args['pagination_type'] !== 'simple'
&&
$args['pagination_type'] !== 'next_prev'
) {
if (intval($args['current_page']) === intval($args['total_pages'])) {
return '';
}
$button_output = '<div class="ct-load-more-helper">' . $button_output;
$button_output .= '<span data-loader="circles"><span></span><span></span><span></span></span>';
$button_output .= '<div class="ct-last-page-text">' . $args['last_page_text'] . '</div>';
$button_output .= '</div>';
}
$pagination_class = 'ct-pagination';
$divider_output = '';
$divider = get_theme_mod(
$args['prefix'] . '_paginationDivider',
[
'width' => 1,
'style' => 'none',
'color' => [
'color' => 'rgba(224, 229, 235, 0.5)',
]
]
);
$numbers_visibility = get_theme_mod(
$args['prefix'] . '_numbers_visibility',
[
'desktop' => true,
'tablet' => true,
'mobile' => false
]
);
$arrows_visibility = get_theme_mod(
$args['prefix'] . '_arrows_visibility',
[
'desktop' => true,
'tablet' => true,
'mobile' => true
]
);
if (
$divider['style'] !== 'none'
&&
$args['pagination_type'] !== 'infinite_scroll'
) {
$divider_output = 'data-divider';
}
$template = '
<nav class="' . $pagination_class . '" data-pagination="' . $args['pagination_type'] . '" ' . $divider_output . '>
%1$s
%2$s
</nav>';
$current_args = \Tainacan\Theme_Helper::get_instance()->get_taxonomies_query_args();
$paginate_links_args = [
'format' => '?termspaged=%#%',
'total' => ceil( $total_terms / $current_args['perpage'] ),
'current' => max( 1, get_query_var('termspaged') ),
'add_args' => array(
'order' => $current_args['order'],
'orderby' => $current_args['orderby'],
'perpage' => $current_args['perpage'],
'search' => $current_args['search'],
'termsparent' => $current_args['termsparent'],
),
'mid_size' => 3,
'end_size' => 0,
'type' => 'array',
'prev_text' => '<svg width="9px" height="9px" viewBox="0 0 15 15"><path class="st0" d="M10.9,15c-0.2,0-0.4-0.1-0.6-0.2L3.6,8c-0.3-0.3-0.3-0.8,0-1.1l6.6-6.6c0.3-0.3,0.8-0.3,1.1,0c0.3,0.3,0.3,0.8,0,1.1L5.2,7.4l6.2,6.2c0.3,0.3,0.3,0.8,0,1.1C11.3,14.9,11.1,15,10.9,15z"/></svg>' . __('Prev', 'blocksy'),
'next_text' => __('Next', 'blocksy') . ' <svg width="9px" height="9px" viewBox="0 0 15 15"><path class="st0" d="M4.1,15c0.2,0,0.4-0.1,0.6-0.2L11.4,8c0.3-0.3,0.3-0.8,0-1.1L4.8,0.2C4.5-0.1,4-0.1,3.7,0.2C3.4,0.5,3.4,1,3.7,1.3l6.1,6.1l-6.2,6.2c-0.3,0.3-0.3,0.8,0,1.1C3.7,14.9,3.9,15,4.1,15z"/></svg>',
];
if ($args['base']) {
$paginate_links_args['base'] = $args['base'];
}
if ( $total_terms <= $current_args['perpage'] )
return '';
$links = paginate_links($paginate_links_args);
$arrow_links = ['', ''];
$proper_links = [];
foreach ($links as $link) {
preg_match('/class="[^"]+"/', $link, $matches);
if (count($matches) === 0) {
continue;
}
if (
$args['pagination_type'] === 'next_prev'
&&
strpos($matches[0], 'next') === false
&&
strpos($matches[0], 'prev') === false
) {
continue;
}
if (
$args['pagination_type'] === 'simple'
&&
(
strpos($matches[0], 'next') !== false
||
strpos($matches[0], 'prev') !== false
)
) {
$link = str_replace(
'page-numbers',
trim('page-numbers ' . blocksy_visibility_classes(
$arrows_visibility
)),
$link
);
}
if (
strpos($matches[0], 'next') !== false
||
strpos($matches[0], 'prev') !== false
) {
$arrow_links[strpos($matches[0], 'next') !== false ? 1 : 0] = $link;
} else {
$proper_links[] = $link;
}
}
$proper_links = join("\n", $proper_links);
if ($args['pagination_type'] === 'simple') {
$proper_links = '<div class="' . blocksy_visibility_classes(
$numbers_visibility
) . '">' . $proper_links . '</div>';
}
echo sprintf(
$template,
$arrow_links[0] . $proper_links . $arrow_links[1],
$button_output
);
}
}
?>

View File

@ -37,6 +37,7 @@ $options = [
'type' => 'ct-layers',
'attr' => [ 'data-layers' => 'title-elements' ],
'design' => 'block',
'manageable' => false,
'value' => $default_hero_elements,
'sync' => '',

View File

@ -0,0 +1,21 @@
<?php
if (! isset($is_general_cpt)) {
$is_general_cpt = false;
}
if (! isset($is_bbpress)) {
$is_bbpress = false;
}
$options = [
[
blocksy_rand_md5() => [
'type' => 'ct-title',
'label' => __( 'Taxonomy terms list', 'tainacan-blocksy' )
]
],
blocksy_get_options(TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/single-elements/tainacan-terms-list-structure.php', [
'prefix' => $post_type->name . '_single'
], false),
];

View File

@ -0,0 +1,126 @@
<?php
if (! isset($prefix)) {
$prefix = '';
} else {
$prefix = $prefix . '_';
}
$options = [
$prefix . 'structure' => [
'label' => false,
'type' => 'ct-image-picker',
'value' => 'simple',
'divider' => 'bottom',
'sync' => blocksy_sync_whole_page([
'prefix' => $prefix,
'loader_selector' => '.entries > article'
]),
'choices' => [
'simple' => [
'src' => blocksy_image_picker_url('simple.svg'),
'title' => __('Simple', 'blocksy'),
],
// 'classic' => [
// 'src' => blocksy_image_picker_url('classic.svg'),
// 'title' => __('Classic', 'blocksy'),
// ],
'grid' => [
'src' => blocksy_image_picker_url('grid.svg'),
'title' => __('Grid', 'blocksy'),
],
]
],
blocksy_rand_md5() => [
'type' => 'ct-condition',
'condition' => [ $prefix . 'structure' => '!grid' ],
'options' => [
$prefix . 'archive_per_page' => [
'label' => __( 'Number of terms', 'tainacan-blocksy' ),
'type' => 'ct-number',
'value' => get_option('posts_per_page', 12),
'min' => 1,
'max' => 500,
'design' => 'inline',
'sync' => blocksy_sync_whole_page([
'prefix' => $prefix,
'loader_selector' => '.entries > article'
]),
],
],
],
blocksy_rand_md5() => [
'type' => 'ct-condition',
'condition' => [ $prefix . 'structure' => 'grid' ],
'options' => [
blocksy_rand_md5() => [
'type' => 'ct-group',
'label' => __( 'Columns & Terms', 'tainacan-blocksy' ),
'attr' => [ 'data-columns' => '2:medium' ],
'responsive' => true,
'options' => [
$prefix . 'columns' => [
'label' => false,
'desc' => __( 'Number of columns', 'blocksy' ),
'type' => 'ct-number',
'value' => [
'desktop' => 3,
'tablet' => 2,
'mobile' => 1
],
'min' => 1,
'max' => 6,
'design' => 'block',
'disableRevertButton' => true,
'attr' => [ 'data-width' => 'full' ],
'sync' => 'live',
'responsive' => true,
'skipResponsiveControls' => true
],
$prefix . 'archive_per_page' => [
'label' => false,
'desc' => __( 'Number of terms', 'tainacan-blocksy' ),
'type' => 'ct-number',
'value' => get_option('posts_per_page', 12),
'min' => 1,
'max' => 200,
'markAsAutoFor' => ['tablet', 'mobile'],
'design' => 'block',
'disableRevertButton' => true,
'attr' => [ 'data-width' => 'full' ],
'sync' => blocksy_sync_whole_page([
'prefix' => $prefix,
'loader_selector' => '.entries > article'
]),
],
],
],
],
],
blocksy_rand_md5() => [
'type' => 'ct-divider',
'attr' => ['data-type' => 'small']
],
$prefix . 'archive_listing_panel' => [
'label' => __('Cards Options', 'blocksy'),
'type' => 'ct-panel',
'value' => 'yes',
'wrapperAttr' => ['data-panel' => 'only-arrow'],
'inner-options' => blocksy_get_options(TAINACAN_BLOCKSY_PLUGIN_DIR_PATH . '/inc/options/single-elements/term-card-options.php', [
'prefix' => $prefix
], false),
],
];

File diff suppressed because it is too large Load Diff

View File

@ -40,3 +40,4 @@
/* Remaining imports */
@import './tainacan-item-archive.scss';
@import './tainacan-item-single.scss';
@import './tainacan-taxonomy-single.scss';

View File

@ -0,0 +1,35 @@
#tainacan-taxonomy-terms-list-form {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
justify-content: space-between;
align-items: end;
margin: 1rem 0 1.5rem;
@media screen and (min-width: 1024px) {
#tainacan-taxonomy-sorting-field {
&>.wp-block-group {
flex-wrap: nowrap !important;
}
}
}
}
.tainacan-taxonomy-terms-list-container {
.entries[data-archive="default"] .entry-card.entry-card {
.term-name {
margin-top: 0.25rem;
margin-bottom: 0.25rem;
}
.term-hierarchy-path {
margin-top: 0px;
margin-bottom: -0.25rem;
}
}
.entries:not([data-layout="grid"]) article > .ct-image-container {
@media (min-width: 690px) {
max-width: 20%;
}
}
}

View File

@ -984,4 +984,35 @@ body:not(.tainacan-admin-page) .tainacan-modal-content .modal-card-body {
margin-bottom: 0.5em;
}
#tainacan-taxonomy-terms-list-form {
display: flex;
flex-wrap: nowrap;
flex-direction: row;
justify-content: space-between;
align-items: end;
margin: 1rem 0 1.5rem;
}
@media screen and (min-width: 1024px) {
#tainacan-taxonomy-terms-list-form #tainacan-taxonomy-sorting-field > .wp-block-group {
flex-wrap: nowrap !important;
}
}
.tainacan-taxonomy-terms-list-container .entries[data-archive="default"] .entry-card.entry-card .term-name {
margin-top: 0.25rem;
margin-bottom: 0.25rem;
}
.tainacan-taxonomy-terms-list-container .entries[data-archive="default"] .entry-card.entry-card .term-hierarchy-path {
margin-top: 0px;
margin-bottom: -0.25rem;
}
@media (min-width: 690px) {
.tainacan-taxonomy-terms-list-container .entries:not([data-layout="grid"]) article > .ct-image-container {
max-width: 20%;
}
}
/*# sourceMappingURL=style.css.map */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,241 @@
<?php
add_filter('tainacan-default-taxonomy-terms-perpage', function() {
$prefix = blocksy_manager()->screen->get_prefix();
return get_theme_mod($prefix . '_archive_per_page', 12);
});
$prefix = blocksy_manager()->screen->get_prefix();
$maybe_custom_output = apply_filters(
'blocksy:posts-listing:canvas:custom-output',
null
);
if ($maybe_custom_output) {
echo $maybe_custom_output;
return;
}
$container_class = 'ct-container';
$section_class = '';
if ( !have_posts() ) {
$section_class = 'class="ct-no-results"';
}
$card_elements = get_theme_mod($prefix . '_archive_order', []);
$hierarchy_element = [ 'enabled' => false ];
$name_element = [ 'enabled' => true, 'heading_tag' => 'h2' ];
$description_element = [ 'enabled' => true, 'excerpt_length' => 20 ];
$thumbnail_element = [ 'enabled' => true ];
$children_link_element = [ 'enabled' => true ];
$items_link_element = [ 'enabled' => true ];
foreach( $card_elements as $card_element ) {
if ( $card_element['id'] == 'hierarchy_path' )
$hierarchy_element = $card_element;
if ( $card_element['id'] == 'title' )
$name_element = $card_element;
if ( $card_element['id'] == 'excerpt' )
$description_element = $card_element;
if ( $card_element['id'] == 'featured_image' )
$thumbnail_element = $card_element;
if ( $card_element['id'] == 'children_link' )
$children_link_element = $card_element;
if ( $card_element['id'] == 'items_link' )
$items_link_element = $card_element;
}
$is_image_boundless = (isset($thumbnail_element['is_boundless']) ? $thumbnail_element['is_boundless'] == 'yes' : true) && (get_theme_mod($prefix . '_card_type', 'boxed') === 'boxed');
$image_size = isset($thumbnail_element['image_size']) ? $thumbnail_element['image_size'] : 'tainacan-large-full';
$hide_term_children_count = (isset($children_link_element['show_term_children_count']) ? $children_link_element['show_term_children_count'] == 'no' : true);
$hide_term_items_count = (isset($items_link_element['show_term_items_count']) ? $items_link_element['show_term_items_count'] == 'no' : true);
?>
<div class="<?php echo $container_class ?>" <?php echo wp_kses_post(blocksy_sidebar_position_attr()); ?> <?php echo blocksy_get_v_spacing() ?>>
<section <?php echo $section_class ?>>
<?php
global $wp_query;
echo '<div id="tainacan-taxonomy-terms-list-form" class="wp-block-group is-wrap is-layout-flex" style="">';
tainacan_the_taxonomies_orderby();
tainacan_the_taxonomies_search( [ 'hide_label' => true ] );
echo '</div>';
$args = [];
$args = wp_parse_args(
$args,
[
'query' => $wp_query,
'prefix' => $prefix,
'has_pagination' => true
]
);
$blog_post_structure = get_theme_mod( $prefix . '_structure', 'simple');
if ( $blog_post_structure === 'type-4' )
$blog_post_structure = 'simple';
if ($args['query']->have_posts()) {
$entries_open = '<div class="entries" ';
$container_output = apply_filters(
'blocksy:posts-listing:container:custom-output',
null
);
$has_cards_type = true;
if ($container_output) {
$hook_id = blc_get_content_block_that_matches([
'template_type' => 'archive'
]);
$atts = blocksy_get_post_options($hook_id);
if (blocksy_akg(
'has_template_default_layout',
$atts,
'yes'
) !== 'yes') {
$has_cards_type = false;
}
$entries_open .= 'data-archive="custom"';
} else {
$entries_open .= 'data-archive="default"';
}
$entries_open .= ' data-layout="' . esc_attr($blog_post_structure) . '"';
if ($has_cards_type) {
$card_type = blocksy_get_listing_card_type([
'prefix' => $prefix
]);
if ($card_type) {
$entries_open .= ' ' . 'data-cards="' . $card_type . '"';
}
}
$entries_open .= ' ' . blocksy_schema_org_definitions('blog');
$archive_order = get_theme_mod(
$prefix . '_archive_order',
[]
);
foreach ($archive_order as $archive_layer) {
if (! $archive_layer['enabled']) {
continue;
}
if ($archive_layer['id'] === 'featured_image') {
$hover_effect = blocksy_akg(
'image_hover_effect',
$archive_layer,
'none'
);
if ($hover_effect !== 'none') {
$entries_open .= ' data-hover="' . $hover_effect . '"';
}
}
}
$entries_open .= ' ' . blocksy_generic_get_deep_link([
'prefix' => $prefix
]) . '>';
do_action('blocksy:loop:before');
$data_reveal_output = '';
if (get_theme_mod(
blocksy_manager()->screen->process_allowed_prefixes(
$args['prefix'],
[
'allowed_prefixes' => ['blog'],
'default_prefix' => 'blog'
]
) . '_has_posts_reveal',
'no'
) === 'yes') {
$data_reveal_output = 'data-reveal="bottom:no"';
}
$entry_open = '<article id="term-id-$id" class="entry-card tainacan-term post type-tainacan-term status-publish format-standard hentry"';
$entry_open .= ' ' . wp_kses_post($data_reveal_output);
$entry_open .= '>';
while (have_posts()) {
the_post();
global $post;
$taxonomy_terms_list = tainacan_get_single_taxonomy_content($post, array(
'before_terms_list' => $entries_open,
'after_term_list' => '</div>',
'before_term' => '<article id="term-id-$id" class="entry-card post type-post status-publish format-standard hentry">',
'after_term' => '</article>',
'before_term_name' => '<' . $name_element['heading_tag'] . ' class="term-name entry-title">',
'after_term_name' => '</' . $name_element['heading_tag'] . '>',
'before_term_description' => '<div class="term-description entry-excerpt"><p>',
'after_term_description' => '</p></div>',
'before_term_information' => '<div class="card-content term-information">',
'after_term_information' => '</div>',
'before_term_links' => '<ul class="entry-meta term-links">',
'after_term_links' => '</ul>',
'before_term_children_link' => '<li class="meta-author term-children-link">',
'after_term_children_link' => '</li>',
'before_term_items_link' => '<li class="meta-date term-items-link">',
'after_term_items_link' => '</li>',
'before_term_thumbnail' => '<figure class="term-thumbnail ct-image-container ' . ( $is_image_boundless ? 'boundless-image' : '' ) .'">',
'after_term_thumbnail' => '</figure>',
'hide_term_children_count' => $hide_term_children_count,
'hide_term_items_count' => $hide_term_items_count,
'term_items_count_position' => 'before',
'term_children_count_position' => 'before',
'hide_term_hierarchy_path' => !$hierarchy_element['enabled'],
'hide_term_name' => !$name_element['enabled'],
'hide_term_thumbnail' => !$thumbnail_element['enabled'],
'hide_term_description' => !$description_element['enabled'],
'hide_term_children_link' => !$children_link_element['enabled'],
'hide_term_items_link' => !$items_link_element['enabled'],
'hide_term_thumbnail_placeholder' => false,
'thumbnails_size' => $image_size,
'trim_description_words' => isset($description_element['excerpt_length']) ? (int)$description_element['excerpt_length'] : 20
));
echo $taxonomy_terms_list['content'];
}
do_action('blocksy:loop:after');
blocksy_tainacan_the_taxonomies_pagination($taxonomy_terms_list['total_terms']);
/**
* Note to code reviewers: This line doesn't need to be escaped.
* Function blocksy_display_posts_pagination() used here escapes the value properly.
*/
if ($args['has_pagination']) {
echo blocksy_display_posts_pagination([
'query' => $args['query'],
'prefix' => $prefix
]);
}
} else {
get_template_part('template-parts/content', 'none');
}
?>
</section>
<?php get_sidebar(); ?>
</div>