Advertisement
Guest User

Untitled

a guest
Sep 28th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.17 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.         echo ggsalas_profile_pagination( $wp_query );
  67.     }
  68. }
  69.  
  70. function ggsalas_profile_pagination( $wp_query ) {
  71.  
  72.     $profile_page_links = paginate_links( array(
  73.         'base' => esc_url( add_query_arg( 'pubs', '%#%' ) ),
  74.         'format' => '',
  75.         'total' => ceil( (int) $wp_query->found_posts / (int) get_query_var('posts_per_page') ),
  76.         'current' => (int) get_query_var('paged'),
  77.  
  78.     ) );
  79.  
  80.     return $profile_page_links;
  81. }
  82.  
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement