From dc5aa58c5045fdca38bd3f58a52d2d9c51b9273a Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Wed, 22 Jul 2020 12:07:11 -0300 Subject: [PATCH] Adds option to change navigation item section label. If no query is passed, uses WordPress default strategy for displaying next and previous links. --- src/functions/customizer.php | 29 +++++++++++++++++-- .../single-items-navigation.php | 21 ++++++++++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/functions/customizer.php b/src/functions/customizer.php index 105b7e5..ed8dfb5 100644 --- a/src/functions/customizer.php +++ b/src/functions/customizer.php @@ -450,6 +450,29 @@ function tainacan_customize_register( $wp_customize ) { 'render_callback' => '__return_false', '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. @@ -633,7 +656,7 @@ function tainacan_customize_register( $wp_customize ) { $wp_customize->add_setting( 'tainacan_single_item_navigation_options', array( 'type' => 'theme_mod', 'capability' => 'edit_theme_options', - 'default' => 'none', + 'default' => 'thumbnail_small', 'transport' => 'refresh', 'sanitize_callback' => 'tainacan_sanitize_single_item_navigation_links_options', ) ); @@ -641,8 +664,8 @@ function tainacan_customize_register( $wp_customize ) { 'type' => 'select', 'priority' => 3, // Within the section. 'section' => 'tainacan_single_item_page', - 'label' => __( 'Navigation links to other 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' ), + 'label' => __( 'Navigation links to adjacent items', '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() ) ); diff --git a/src/template-parts/single-items-navigation.php b/src/template-parts/single-items-navigation.php index 34f60b5..ae79dab 100644 --- a/src/template-parts/single-items-navigation.php +++ b/src/template-parts/single-items-navigation.php @@ -14,6 +14,17 @@ } else { $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 { //Get the links to the Previous and Next Post $previous_link_url = get_permalink( get_previous_post() ); @@ -27,7 +38,7 @@ $previous = ''; $next = ''; - switch (get_theme_mod('tainacan_single_item_navigation_options', 'none')) { + switch (get_theme_mod('tainacan_single_item_navigation_options', 'thumbnail_small')) { case 'link': $previous = $previous_link_url === false ? '' : ''; @@ -94,9 +105,13 @@ return ''; } ?> - +
-

+ +

+ +

+