• pikamo

    (@pikamo)


    Hi,
    i have create a plugin with wp_liste_table. I dont know how to get data in front page template with pagination.
    this my code:

    function images_section_shortcode() {
            global $wpdb;
            $table_name=$wpdb->prefix.'sectionimages';
    
            $results = $wpdb->get_results( "SELECT * FROM $table_name",OBJECT );
            $content = "";
            ob_start();
            $templatefilename = 'images-section-list-template.php';
            include  dirname( __FILE__ ) . '/' . $templatefilename;
            return ob_get_clean();  
        }
    add_shortcode( 'images_shortcode','images_section_shortcode');

    Thanks.

Viewing 1 replies (of 1 total)
  • Thread Starter pikamo

    (@pikamo)

    hi; i have this code:

    global $wpdb;
    $per_page = 5;
    $page = isset( $_GET['cpage'] ) ? abs( (int) $_GET['cpage'] ) : 1;
    if ($page > 1) {
        $offset = $page * $per_page - $per_page;
    } else {
        $offset = $page;
    }
    $the_post = "select id,post_title from $wpdb->posts where post_type in ('buy','rent') and post_status='publish' "
            . "order by id desc limit $per_page offset $offset";
    $details = $wpdb->get_results($the_post, OBJECT);
    //do foreach to display your post details.
    
    //paste this, where you want to display the pagination
    $total = $wpdb->get_var("SELECT count(id) from $wpdb->posts where post_type in ('buy','rent') and post_status='publish' order by id desc");
    echo paginate_links(array(
        'base' => add_query_arg('cpage', '%#%'),
        'format' => '',
        'prev_text' => __('«'),
        'next_text' => __('»'),
        'total' => ceil($total / $per_page),
        'current' => $page
    ));

    but hi not give me the first records !!

Viewing 1 replies (of 1 total)
  • The topic ‘plugin wp_list_table with pagination in front page’ is closed to new replies.