Adds option to change navigation item section label. If no query is passed, uses WordPress default strategy for displaying next and previous links.

This commit is contained in:
mateuswetah 2020-07-22 12:07:11 -03:00
parent d20a000303
commit dc5aa58c50
2 changed files with 44 additions and 6 deletions

View File

@ -450,6 +450,29 @@ function tainacan_customize_register( $wp_customize ) {
'render_callback' => '__return_false', 'render_callback' => '__return_false',
'fallback_refresh' => true 'fallback_refresh' => true
) ); ) );
/**
* Adds option to configure Item Navigation section label.
*/
$wp_customize->add_setting( 'tainacan_single_item_navigation_section_label', array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'default' => __('Continue browsing', 'tainacan-interface'),
'transport' => 'postMessage',
'sanitize_callback' => 'sanitize_text_field'
) );
$wp_customize->add_control( 'tainacan_single_item_navigation_section_label', array(
'type' => 'text',
'priority' => 0, // Within the section.
'section' => 'tainacan_single_item_page',
'label' => __( 'Label for the "Items navigation" or "Continue browsing" section', 'tainacan-interface' ),
'description' => __( 'Leave blank it for not displaying any label.', 'tainacan-interface' )
) );
$wp_customize->selective_refresh->add_partial( 'tainacan_single_item_navigation_section_label', array(
'selector' => '#single-item-navigation-label',
'render_callback' => '__return_false',
'fallback_refresh' => true
) );
/** /**
* Adds options to hide attachments file names on carousel. * Adds options to hide attachments file names on carousel.
@ -633,7 +656,7 @@ function tainacan_customize_register( $wp_customize ) {
$wp_customize->add_setting( 'tainacan_single_item_navigation_options', array( $wp_customize->add_setting( 'tainacan_single_item_navigation_options', array(
'type' => 'theme_mod', 'type' => 'theme_mod',
'capability' => 'edit_theme_options', 'capability' => 'edit_theme_options',
'default' => 'none', 'default' => 'thumbnail_small',
'transport' => 'refresh', 'transport' => 'refresh',
'sanitize_callback' => 'tainacan_sanitize_single_item_navigation_links_options', 'sanitize_callback' => 'tainacan_sanitize_single_item_navigation_links_options',
) ); ) );
@ -641,8 +664,8 @@ function tainacan_customize_register( $wp_customize ) {
'type' => 'select', 'type' => 'select',
'priority' => 3, // Within the section. 'priority' => 3, // Within the section.
'section' => 'tainacan_single_item_page', 'section' => 'tainacan_single_item_page',
'label' => __( 'Navigation links to other items', 'tainacan-interface' ), 'label' => __( 'Navigation links to adjacent items', 'tainacan-interface' ),
'description' => __( 'Sets how next and previous items links will be displayed. This links only obey creation date order inside their collection.', 'tainacan-interface' ), 'description' => __( 'Sets how next and previous items links will be displayed. If your Tainacan version is bellow 0.17, this links only obey creation date order inside their collection.', 'tainacan-interface' ),
'choices' => tainacan_get_single_item_navigation_links_options() 'choices' => tainacan_get_single_item_navigation_links_options()
) ); ) );

View File

@ -14,6 +14,17 @@
} else { } else {
$previous_link_url = false; $previous_link_url = false;
} }
// In this case, the user entered the page without any query params.
if (!isset($adjacent_items['previous']) && !isset($adjacent_items['previous'])) {
//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() );
}
} else { } else {
//Get the links to the Previous and Next Post //Get the links to the Previous and Next Post
$previous_link_url = get_permalink( get_previous_post() ); $previous_link_url = get_permalink( get_previous_post() );
@ -27,7 +38,7 @@
$previous = ''; $previous = '';
$next = ''; $next = '';
switch (get_theme_mod('tainacan_single_item_navigation_options', 'none')) { switch (get_theme_mod('tainacan_single_item_navigation_options', 'thumbnail_small')) {
case 'link': case 'link':
$previous = $previous_link_url === false ? '' : '<a rel="prev" href="' . $previous_link_url . '"><i class="tainacan-icon tainacan-icon-arrowleft tainacan-icon-30px"></i>&nbsp; ' . $previous_title . '</a>'; $previous = $previous_link_url === false ? '' : '<a rel="prev" href="' . $previous_link_url . '"><i class="tainacan-icon tainacan-icon-arrowleft tainacan-icon-30px"></i>&nbsp; ' . $previous_title . '</a>';
@ -94,9 +105,13 @@
return ''; return '';
} }
?> ?>
<?php if ($previous !== '' && $next !== '') : ?> <?php if ($previous !== '' || $next !== '') : ?>
<div class="tainacan-single-post"> <div class="tainacan-single-post">
<h2 class="title-content-items"><?php echo __('Also in this collection', 'tainacan-interface') ?></h2> <?php if ( get_theme_mod('tainacan_single_item_navigation_section_label', __( 'Continue browsing', 'tainacan-interface' )) != '') : ?>
<h2 class="title-content-items" id="single-item-navigation-label">
<?php echo get_theme_mod('tainacan_single_item_navigation_section_label', __('Continue browsing', 'tainacan-interface')); ?>
</h2>
<?php endif; ?>
<div id="item-single-navigation" class="d-flex justify-content-between margin-two-column"> <div id="item-single-navigation" class="d-flex justify-content-between margin-two-column">
<div class="pagination"> <div class="pagination">
<?php echo $previous; ?> <?php echo $previous; ?>