Skip Navigation

[Resuelto] How to integrate a link to previous and next post inside a Forms (modification)

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I have a Form that is uesd to edit posts. I would like to include a next and previous post link so that I can edit the next or previous post easily without returning to a list of posts.

Solution: Create a paginated, filtered View that displays only 1 post, using AJAX pagination updates. In the Loop Output editor for this View, place an Edit Post Form. Place this View on a custom Page.

In another custom Page, place a filtered View that shows all the posts. Next to each post, create a custom edit post link that directs the User to the other custom Page, using a pagination URL parameter based on the loop iteration.

add_shortcode( 'loop-iteration', function( $atts ){
  
    global $loop_n;
  
    if ( !isset( $loop_n ) ) {
        $loop_n = 1;
        return $loop_n;
    }
  
    $loop_n++;
  
    if ( !isset( $atts['n'] ) ) {
        // no nth parameter, just return the current index
        return $loop_n;
    }
    else {
        $remainder = ( $loop_n + 1 ) % $atts['n'];
        return ( $remainder == 0 );
    }
  
});
<a href="/view-2-page?wpv_paged=[loop-iteration]">[wpv-post-title]</a>
This support ticket is created hace 6 años, 4 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Etiquetado: 

Este tema contiene 17 respuestas, tiene 3 mensajes.

Última actualización por Pat hace 6 años, 4 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#923880

Pat

Hi Christian,

I have changed a little your code in order to make it work. Here is the latest version :

/**
* Add loop-iteration shortcode
*
* Attributes
* 'n' (optional) : test for nth iteration
*/
add_shortcode( 'loop-iteration', function( $atts ){

global $loop_n;

if ( !isset( $loop_n ) ) {
$loop_n = 0;
return $loop_n + 1;
}

$loop_n++;

if ( !isset( $atts['n'] ) ) {
// no nth parameter, just return the current index
return $loop_n + 1;
}
else {
$remainder = ( $loop_n + 1 ) % $atts['n'];
return ( $remainder == 0 );
}

});

Now, it's working but I not sure to have all potential cases covered.
Can you have a look onit please?
Regards
Pat

#924180

I think to start at 1 I would change the original code to start with $loop_n = 1 instead of 0:

add_shortcode( 'loop-iteration', function( $atts ){
 
    global $loop_n;
 
    if ( !isset( $loop_n ) ) {
        $loop_n = 1;
        return $loop_n;
    }
 
    $loop_n++;
 
    if ( !isset( $atts['n'] ) ) {
        // no nth parameter, just return the current index
        return $loop_n;
    }
    else {
        $remainder = ( $loop_n + 1 ) % $atts['n'];
        return ( $remainder == 0 );
    }
 
});
#924502

Pat

Hi Christian.

Perfect
Many thanks
Pat