Advertisement
Guest User

Untitled

a guest
Sep 28th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.16 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'                  => 'Myposts',
  17.       'slug'                  => 'myposts',
  18.       'parent_url'            => $bp->displayed_user->domain,
  19.       'parent_slug'           => $bp->profile->slug,
  20.       'screen_function'       => 'mis_publicaciones',
  21.       'position'              => 70,
  22.       'default_subnav_slug'   => '/',
  23.     ));
  24. }
  25. add_action( 'bp_setup_nav', 'bp_content_setup_nav1',100 );
  26.  
  27.  
  28. function mis_publicaciones() {
  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_content() {
  34.     global $post;
  35.     global $bp;
  36.  
  37.     $paged = ( isset( $_GET['pubs'] ) ) ? $_GET['pubs'] : 1;
  38.     $args = array(
  39.         'post_type'      => 'post',
  40.         'post_status'    => 'publish',
  41.         'posts_per_page' => 2,
  42.         'author'     => bp_displayed_user_id(),
  43.         'paged'          => $paged
  44.     );
  45.  
  46.     /**
  47.      * Loop
  48.      */
  49.  
  50.     // The Query
  51.     $wp_query = new WP_Query( $args );
  52.  
  53.     // The Loop
  54.     if ( $wp_query->have_posts() ) {
  55.         while ( $wp_query->have_posts() ) {
  56.             $wp_query->the_post();
  57.             ?>
  58.             <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
  59.             <?php
  60.         }
  61.  
  62.         echo ggsalas_profile_pagination( $wp_query );
  63.     }
  64. }
  65.  
  66. function ggsalas_profile_pagination( $wp_query ) {
  67.  
  68.     $profile_page_links = paginate_links( array(
  69.         'base'         => @add_query_arg('pubs','%#%'),
  70.         'format'       => '?pubs=%#%',
  71.         'total' => ceil( (int) $wp_query->found_posts / (int) get_query_var('posts_per_page') ),
  72.         'current' => (int) get_query_var('paged'),
  73.         'show_all'     => true,
  74.         'type'         => 'plain'
  75.     ));
  76.  
  77.     // Output pagination
  78.     return $profile_page_links;
  79. }
  80.  
  81. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement