Monday, December 26, 2022
HomeWordPress Developmentplugins - How you can get URL param for pagination in shortcode?

plugins – How you can get URL param for pagination in shortcode?


I’ve made the shortcode which shows knowledge from database.
There are such a lot of rows and so I made pagination.
However I am unable to get the URL param which suggests web page quantity.

<?php

/**
 * Plugin Identify: Plugin hell
 */

if (!outlined('ABSPATH')) {
    die;
}

operate count_rows()
{
    international $wpdb;
    $table_name = $wpdb->prefix . 'strong_concordance';
    $rely = $wpdb->get_var("SELECT COUNT(*) FROM $table_name");
    return intval($rely);
}
operate get_data($offset, $per_page)
{
    international $wpdb;
    $table_name = $wpdb->prefix . 'strong_concordance';
    $knowledge = $wpdb->get_results("SELECT * FROM $table_name LIMIT $offset, $per_page");
    return $knowledge;
}


operate display_data_shortcode($atts)
{
    $atts = shortcode_atts(
        array(
            'web page' => 1,
            'per_page' => 10,
        ), $atts, 'display_data');

    //$web page = intval($atts['page']);
    $web page = (get_query_var('web page')) ? get_query_var('web page') : 1;
    var_dump($web page);

    $per_page = intval($atts['per_page']) ? : 10;

    $num_pages = ceil(count_rows() / $per_page);

    $offset = ($web page - 1) * $per_page;

    $knowledge = get_data($offset, $per_page);
    
    $output="";
    foreach ($knowledge as $row) {
        $output .= '<h3>' . $row->strong_reference . '</h3>';
        $output .= '<p model="font-weight: daring;">' . $row->greek_word . '</p>';
        $output .= '<p>' . $row->rationalization . '</p>';
    }
    

    if ($web page > 1) {
        $output .= '<a href="?web page=" . ($web page - 1) . "">Earlier</a>';
    }
    for ($i = 1; $i <= $num_pages; $i++) {
        $output .= '<a href="?web page=" . $i . "">' . ' ' . $i . ' ' . '</a>';
    }
    if ($web page < $num_pages) {
        $output .= '<a href="?web page=" . ($web page + 1) . "">Subsequent</a>';
    }

    return $output;
}

add_shortcode('display_data', 'display_data_shortcode');

?>

There will probably be web page numbers like “1 2 3 4 5 … “.
I click on any number-for instance 4, the $web page needs to be 4 and so $offset needs to be 30, however the $web page remains to be 1 and so there will probably be identical knowledge.
How can I resolve this challenge?

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments