• Resolved Reobed

    (@reobed)


    Hello, I have an AWPCP plugin installed and have created a snippet to show classifieds/posts only from the City of Amsterdam. Now this works fine, but the list is too long, as I will have about 1500 posts. So I need a pagination. How do I do this in the Codesnippets plug in, and where do I put the code.

    I have tried several ways but no way that I see a pagination like << prev next>>
    or a page 1,2,3, >> etc

    I figured that this pagination code should be either already existing and “called” for in the below snippet, or some extra snippet code should be entered in the below snippet…but which, where….no clue. Please advice
    ===============================================================================
    /**
    * Adds Widget
    */
    class Amsterdam_Widget extends WP_Widget {

    /**
    * Register widget with WordPress.
    */
    function __construct() {
    parent::__construct(
    ‘beloning_widget’, // Base ID
    esc_html__( ‘Niet in lijst? bel 0900-9299’, ‘text_domain’ ), // Name
    array( ‘description’ => esc_html__( ‘Amsterdam Widget’, ‘text_domain’ ), ) // Args
    );
    }

    public function widget( $args, $instance ) {
    echo $args[‘before_widget’];
    if ( ! empty( $instance[‘title’] ) ) {
    echo $args[‘before_title’] . apply_filters( ‘widget_title’, $instance[‘title’] ) . $args[‘after_title’];
    }
    // echo esc_html__( ‘hieronder een lijst alle Amsterdam meldingen’, ‘dit is een widget’ );
    // echo $args[‘after_widget’];

    ?>
    <table bgcolor=”#f7f7f7″ border=”0″>
    <tr>
    <th>Datum</th>
    <th>Omschrijving</th>

    </tr>

    <?php
    global $wpdb;
    // !!!!!!! Let op!!! Voor beloningen is het veld ‘ad_state” gebruikt !!!!!
    $result = $wpdb->get_results ( “SELECT wp_awpcp_ads.ad_id,
    wp_awpcp_ads.ad_title,
    wp_awpcp_ads.ad_postdate,
    wp_awpcp_ads.ad_category_parent_id,
    wp_awpcp_ad_regions.ad_id,
    wp_awpcp_ad_regions.state,
    wp_awpcp_ad_regions.city

    FROM
    wp_awpcp_ads, wp_awpcp_ad_regions
    WHERE
    wp_awpcp_ads.ad_id = wp_awpcp_ad_regions.ad_id
    AND
    wp_awpcp_ad_regions.city = ‘Amsterdam’
    ORDER BY
    wp_awpcp_ads.ad_id desc limit 100”);

    // $result = $wpdb->get_results ( “SELECT wp_awpcp_ads.ad_id, wp_awpcp_ad.regions.city FROM wp_awpcp_ads WHERE city = ‘Amsterdam’ ORDER BY ad_id DESC”);
    foreach ( $result as $print ) {
    echo ‘<tr>’;

    echo ‘<td>ad_id) . ‘>’ . $print->ad_postdate .'</td>’;

    // volgende regel is voor contole om te kijken of het een 1 of 2 is
    //echo ‘<td>
    ad_id) . ‘>’ . $print->ad_category_parent_id .'</td>’;

    echo ‘<td style=”text-align:left”>ad_id) . ‘>’ . $print->ad_title .'</td>’;
    echo ‘<td> ad_category_parent_id .’.jpg” height=”50″ width=”50″></td>’;

    echo ‘</tr>’;
    }

    ?>

    </table>
    <?php

    }

    /**
    * Back-end widget form.
    *
    * @see WP_Widget::form()
    *
    * @param array $instance Previously saved values from database.
    */
    public function form( $instance ) {
    $title = ! empty( $instance[‘title’] ) ? $instance[‘title’] : esc_html__( ‘Niet in lijst? bel 0900-9299’, ‘text_domain’ );
    ?>
    <p>
    <label for=”<?php echo esc_attr( $this->get_field_id( ‘title’ ) ); ?>”><?php esc_attr_e( ‘Title:’, ‘text_domain’ ); ?></label>
    <input class=”widefat” id=”<?php echo esc_attr( $this->get_field_id( ‘title’ ) ); ?>” name=”<?php echo esc_attr( $this->get_field_name( ‘title’ ) ); ?>” type=”text” value=”<?php echo esc_attr( $title ); ?>”>
    </p>
    <?php
    }

    public function showusers() {
    $user_count = $wpdb->get_var( “SELECT COUNT(*) FROM $wpdb->users” );
    echo “<p>User count is {$user_count}</p>”;
    }

    /**
    * Sanitize widget form values as they are saved.
    *
    * @see WP_Widget::update()
    *
    * @param array $new_instance Values just sent to be saved.
    * @param array $old_instance Previously saved values from database.
    *
    * @return array Updated safe values to be saved.
    */
    public function update( $new_instance, $old_instance ) {
    $instance = array();
    $instance[‘title’] = ( ! empty( $new_instance[‘title’] ) ) ? strip_tags( $new_instance[‘title’] ) : ”;

    return $instance;
    }

    } // class Foo_Widget

    // register Plaats_Widget
    function register_Amsterdam_widget() {
    register_widget( ‘Amsterdam_Widget’ );
    }
    add_action( ‘widgets_init’, ‘register_Amsterdam_widget’ );

    =============================================================================

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Pagination’ is closed to new replies.