Guest User

pagination problem on buddypress tab

a guest
Sep 28th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.   Plugin Name: [pulperia]  My posts
  5.   Plugin URI:
  6.   Description: Post list from the displayed user as author
  7.   Version: 1.0
  8.   Author: GGsalas
  9.   Author URI: http://ggsalas.com
  10. */
  11.  
  12. function bp_content_setup_nav1() {
  13.     global $bp;
  14.  
  15.     bp_core_new_nav_item( array(
  16.       'name'                  => __('Publicaciones', 'buddypress'),
  17.       'slug'                  => 'posts',
  18.       'parent_url'            => trailingslashit( bp_displayed_user_domain() . '/' ),
  19.       'screen_function'       => 'mis_publicaciones',
  20.       'position'              => 70,
  21.       'default_subnav_slug'   => '/',
  22.     ));
  23. }
  24. add_action( 'bp_setup_nav', 'bp_content_setup_nav1' );
  25.  
  26.  
  27. function mis_publicaciones() {
  28.     add_action( 'bp_template_title', 'mis_publicaciones_title' );
  29.     add_action( 'bp_template_content', 'mis_publicaciones_content' );
  30.     bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
  31. }
  32.  
  33. function mis_publicaciones_title() {
  34.     echo "Posts";
  35. }
  36.  
  37. function mis_publicaciones_content() {
  38.     global $post;
  39.     global $bp;
  40.  
  41.     $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
  42.     $args = array(
  43.         'post_type'      => 'post',
  44.         'post_status'    => 'publish',
  45.         'posts_per_page' => 2,
  46.         'author'         => bp_displayed_user_id(),
  47.         'paged'          => $paged
  48.     );
  49.  
  50.     /**
  51.      * Loop
  52.      */
  53.  
  54.     // The Query
  55.     $wp_query = new WP_Query( $args );
  56.  
  57.     // The Loop
  58.     if ( $wp_query->have_posts() ) {
  59.         while ( $wp_query->have_posts() ) {
  60.             $wp_query->the_post();
  61.             ?>
  62.             <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
  63.             <?php
  64.         }
  65.  
  66.         /*
  67.          * Pagination links
  68.          * https://codex.wordpress.org/Function_Reference/paginate_links
  69.          */
  70.         $big = 999999999; // need an unlikely integer
  71.         echo paginate_links( array(
  72.             'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
  73.             'format' => '?paged=%#%',
  74.             'current' => max( 1, get_query_var('paged') ),
  75.             'total' => $wp_query->max_num_pages
  76.         ) );
  77.     }
  78. }
  79.  
  80. ?>
Advertisement
Add Comment
Please, Sign In to add comment