Minesh,
I want to share the solution I've developed with the help of ChatGPT.
## Next/Previous Navigation for "Tratamientos" (treatment) Filtered by "zona corporal" (body area)
### Objective
To add navigation links that allow users to move to the next or previous treatment, sorted alphabetically and filtered by the body area (facial or corporal) selected by the user.
### General Structure
* **Custom Post Type:** `tratamiento` (treatment)
* **Custom Taxonomy:** `zona-corporal` (body-area)
* **Slugs used:** `facial` and `corporal`
* Body areas can be associated with more than one term, but navigation is forced to respect the one passed via the URL.
* Navigation uses the `?zona-corporal=facial` or `?zona-corporal=corporal` parameter to determine the navigation group.
### Custom Code
The following PHP code was added from:
**Toolset > Settings > Custom Code**
```php
function navegacion_tratamiento_por_zona_param_shortcode() {
if ( !is_singular('tratamiento') ) {
return '';
}
global $post;
$zona_slug = isset($_GET['zona-corporal']) ? sanitize_text_field($_GET['zona-corporal']) : '';
if ( empty($zona_slug) ) return '';
$zona = get_term_by('slug', $zona_slug, 'zona-corporal');
if ( !$zona ) return '';
$args = array(
'post_type' => 'tratamiento',
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'zona-corporal',
'field' => 'term_id',
'terms' => $zona->term_id,
),
),
'fields' => 'ids',
);
$posts = get_posts($args);
$current_index = array_search($post->ID, $posts);
$output = '<div class="navegacion-posts">';
if ($current_index > 0) {
$prev_id = $posts[$current_index - 1];
$output .= '<div class="post-anterior">';
$output .= '<div class="etiqueta">Previous</div>'; // Translated from 'Anterior'
$output .= '← ' . get_the_title($prev_id) . '';
$output .= '</div>';
}
if ($current_index < count($posts) - 1) {
$next_id = $posts[$current_index + 1];
$output .= '<div class="post-siguiente">';
$output .= '<div class="etiqueta">Next</div>'; // Translated from 'Siguiente'
$output .= '' . get_the_title($next_id) . ' →';
$output .= '</div>';
}
$output .= '</div>';
return $output;
}
add_shortcode('navegacion_tratamiento_por_zona', 'navegacion_tratamiento_por_zona_param_shortcode');
```
### Shortcode Insertion
The shortcode `[navegacion_tratamiento_por_zona]` was inserted at the bottom of the content template created with Toolset:
* **Template Name:** Template for Treatments
* **Block Type:** Shortcode
### Links with Parameter
On the page displaying the treatments, (hidden link) two Views filtered by `zona-corporal` are used: facial and corporal.
Each item in the list includes a link constructed as follows:
**Toolset Block used:** Fields and Text
* **For Facial Area:**
`[wpv-post-title]`
* **For Corporal Area:**
`[wpv-post-title]`
### CSS Styles
CSS from **Appearance > Customize > Additional CSS:**
```css
.navegacion-posts {
display: flex;
justify-content: space-between;
margin: 2em 0;
gap: 2em;
}
.navegacion-posts .post-anterior,
.navegacion-posts .post-siguiente {
flex: 1;
}
.navegacion-posts .etiqueta {
font-weight: bold;
font-size: 0.9em;
margin-bottom: 0.3em;
text-transform: uppercase;
color: #555;
}
```
And that's it!
thanks for your help!
me