Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Show posts written by user on profile

  • @djduckworth

    Member

    Is it possible to add a new link to the profile which displays the posts written by the user?

    By plugin would be ideal, but I can also modify the theme.

Viewing 25 replies - 26 through 50 (of 51 total)
  • @anywherebuthollywood

    Participant

    Let’s try that again:

    // adding a subnav menu tab on a profile page for author's posts
    // add this snippet into theme's functions.php
    
    function authorposts_onprofile() {
    global $bp;
    	?>
    	<li id="activity-reshares"><a href="<?php echo home_url(). '/author/' . bp_get_displayed_user_username(). '/'; ?>" title="<?php bp_displayed_user_fullname(); ?>'s Posts">Posts</a></li>
    	<?php
    }
    
    add_action('bp_member_options_nav', 'authorposts_onprofile'); 

    @tecca

    Participant

    That works to add a tab, but I think the idea here is to show posts within the author’s BuddyPress profile.

    @hughshields

    Participant

    This topic says resolved but I am not able to get posts to show on the profile. After reading the above thread multiple times here is what I did:
    1. Downloaded an updated version of BP Posts on Profile revised by @azchipka called “TCH-BuddyPress-Posts-On-Profile”, installed, and activated it.
    2. Added the code offered by @anywherebuthollywood to the functions.php file in my child theme.

    The “My Profile” tab does appear but if I click on it I get the same empty blog page with “Members” in the header and whichever logged in user showing up as a link to the logged in author’s page.

    Did I miss a step or is this not resolved after all?

    @henrywright-1

    Member

    The way I would show posts on a BuddyPress profile would be like this:

    
    $args = array( 'author' => bp_displayed_user_id(),
                    'post_type' => 'post'
            );
    query_posts( $args );
    if ( have_posts() ) : while ( have_posts() ) : the_post();
    // do something amazing
    endwhile; else:
    // no posts found so do something less amazing
    endif;
    wp_reset_postdata();
    

    @fitnessblogger

    Participant

    Hi @henry and @hughshields

    I am also trying to get this to work on my site…

    I have the plugin from @azchipka

    and I have the tab “My posts”

    Where would i add the above code ???

    Sorry I am a bit of a BP Newbie Still!!!

    Cheers

    James

    @henrywright-1

    Member

    @fitnessblogger you’d add it to the members/single/profile.php file

    Make sure you include the opening and closing PHP tags or it won’t work <?php and ?>

    @hughshields

    Participant

    Thanks @henrywright-1
    I looked in members/single/profile.php. Where would I drop in your code?

    <?php if ( bp_is_my_profile() ) : ?>
    	<div class="item-list-tabs no-ajax" id="subnav">
    		<ul>
    			<?php bp_get_options_nav() ?>
    		</ul>
    	</div>
    <?php endif; ?>
    
    <?php do_action( 'bp_before_profile_content' ) ?>
    
    <div class="profile">
    	<?php if ( 'edit' == bp_current_action() ) : ?>
    		<?php locate_template( array( 'members/single/profile/edit.php' ), true ) ?>
    
    	<?php elseif ( 'change-avatar' == bp_current_action() ) : ?>
    		<?php locate_template( array( 'members/single/profile/change-avatar.php' ), true ) ?>
    
    	<?php else : ?>
    		<?php locate_template( array( 'members/single/profile/profile-loop.php' ), true ) ?>
    
    	<?php endif; ?>
    </div><!-- .profile -->
    
    <?php do_action( 'bp_after_profile_content' ) ?>

    @hughshields

    Participant

    The plugin by @azchipka called β€œTCH-BuddyPress-Posts-On-Profile” gets the job half way done and successfully creates a tab on the member profile, but it looks like there is a problem with the code when displaying member posts. Firstly it links to a new page and doesn not display posts within the tab on the member profile, and secondly it does not display any posts. Here is the code. anyone care to take a swing at fixing this:

    // show feedback when 'Posts' tab is clicked
    function bp_postsonprofile() {
    add_action( 'bp_template_content', 'profile_screen_posts_show' );
    bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    
    function profile_screen_posts_show() {
    $theuser = bp_displayed_user_id(); 
    query_posts("author=$theuser" );
    if ( have_posts() ) :
    get_template_part( 'loop', 'archive' );
    else: ?>
    <div id="message" class="info">
    		<p><?php _e( 'Sorry, this user has not published any posts.', 'buddypress' ); ?></p>
    	</div><?php endif; ?>    <?php
    } 
    }
    ?>

    @henrywright-1

    Member

    @hughshields If you’re just getting started with PHP and prefer a plugin, try BuddyBlog – http://buddydev.com/plugins/buddyblog/ and Simple Front End Post http://buddydev.com/plugins/bp-simple-front-end-post/

    You can let your members blog directly from their BuddyPress profile. A list of posts on profile comes as standard too.

    @hughshields

    Participant

    Thanks @henrywright-1
    I did look at Buddyblog but didn’t know that a list of posts on profile comes standard. I actually don’t want my users to blog from their profile. I just want to show a list of blog posts on my member profiles. In any case I will check it out.

    It seems a pity that the simple Posts in Profile plugin cannot be fixed. I posted on this subject 7 months ago and no one has been able to make it work. It also seems like a highly visible and critical piece to Buddypress WordPress integration. Anyone using WordPress and thinking of adding BP social networking features will want this.

    Guess I will let it go!

    @hughshields

    Participant

    @henrywright-1. you were right. BuddyBlog does show posts on profile and very nicely, although on the download page it doesn’t mention this fact. So BuddyBlog is a good solution for me. Thanks!
    It is easier for me to take a plugin that works and turn off features (like blogging from profile) than to try to fix one that is broken.

    Here is the link again for other interested folks:
    BuddyBlog – http://buddydev.com/plugins/buddyblog/

    Much obliged!

    @fitnessblogger

    Participant

    Hello @hughshields and @henrywright-1

    I found this comment over on @azchipka blog

    “the plugin is looking for /members/username/posts/ but should be looking for /author/username/”

    I don’t think the plugin is broken I think it was made for a specific site and just needs a bit of a tweak to get it to work ??


    @azchipka
    says “Sounds like we are using a different directory structure then you are. You can adjust the path in the plugin file and that should resolve the issue.”

    Would anyone know what code I would use to achieve this ??

    I would really love to get this plugin working

    Kind Regards

    James

    @henrywright-1

    Member

    @fitnessblogger when @azchipka says adjust the path in the plugin to achieve /author/username I assume that means just getting rid of /posts/? I’m not familiar with the plugin. @azchipka should be able to help with specifics.

    If you just want to show posts on a BP profile then my code should work:

    https://buddypress.org/support/topic/resolved-show-posts-written-by-user-on-profile/page/2/#post-172143

    Alternatively the plugins I mentioned earlier by buddydev.com are brilliant.

    @fitnessblogger

    Participant

    Thanks @henrywright-1

    I have sent @azchipka a message – I was keen to get this to work as it has been puzzling me!!

    But I will have a look at your code and BuddyDev plugin too

    Thanks for your help πŸ™‚

    @hughshields

    Participant

    BuddyBlog is a great plugin. Thanks @henrywright-1 for pointing me to it.
    The only problem is that it does too much. It displays posts on profile which is great. But it also adds a sub-nav on my own profile to add a New Post, which I don’t want.
    I have dug through all the files in the plugin looking for the sub-navigation to try and hide the New Post button, but no luck.
    Can someone point me in the right direction?
    Much obliged.

    @henrywright-1

    Member

    @hughshields have you thought about a CSS solution?

    #posts-personal-li {
       display: none;
    }
    #edit-personal-li {
       display: none;
    }

    @hughshields

    Participant

    Great! Thanks @henrywright-1! I didn’t even think of CSS. Works perfectly.

    So @fitnessblogger, with BuddyBlog and the one line of CSS provided by Henry above you basically have a Posts in Profile solution that works perfectly. Users can view each other’s posts in a tab on their profile and will not be able to blog from their own profile because that sub-navigation feature is hidden.

    That resolves it for me. Thanks again!

    @lucamoretto

    Participant

    Hi guys is the same if i wannainsert a list of all products uploaded by author in my site woocommerce + buddypress. Every users (subscriber) can upload a new products, I wanna display in the user buddypress profile a list with a link of all products published by author. Is Possible? Can help me to solve this problem? Ty in advance!

    @bmstudio

    Participant

    Hi,

    I have modify the @azchipka ‘s plugin.
    It’s work !!!

    
    <?php
    /*
    Plugin Name: TCH BP Posts On Profile
    Plugin URI: http://azchipka.thechipkahouse.com/services/technology/development/wordpress-plugins
    Description: Adds a tab to Buddy Press User Profile displaying the posts they have published. 
    Version: 0.1
    Author: Avery Z Chipka
    Author URI: http://azchipka.thechipkahouse.com
    License: GPLv2 or later
    */
    // Make sure we don't expose any info if called directly
    
    if ( !function_exists( 'add_action' ) ) {
    	echo '404';
    	exit;
    }
    define('TCH_PostsOnProfilesVersion', '0.1');
    define('TCH_PostsOnProfilesVersion_PLUGIN_URL', plugin_dir_url( __FILE__ ));
    
    function my_setup_nav() {
          global $bp;
     
          bp_core_new_nav_item( array( 
            'name' => __( 'Outils', 'buddypress' ), 
            'slug' => 'mes-outils', 
            'position' => 75,
            'screen_function' => 'mes_outils_lien',
    	    'show_for_displayed_user' => true,
    	    'default_subnav_slug' => 'mes-outils',
    	    'item_css_id' => 'mes-outils'
          ) );
    }
     
    add_action( 'bp_setup_nav', 'my_setup_nav', 1000 );
     
    function mes_outils_titre() {
    	echo 'Mes outils';
    }
     
    function mes_outils_contenu() {
    		locate_template( array( 'members/single/outils/loop-outils.php' ), true ) ?>
        	<?php echo "TEST"; ?>
            
        <?php
    }
     
    function mes_outils_lien () {
    	add_action( 'bp_template_title', 'mes_outils_titre' );
    	add_action( 'bp_template_content', 'mes_outils_contenu' );
    	bp_core_load_template( apply_filters( 'bp_core_template_plugin', 'members/single/plugins' ) );
    }
    ?>

    @bmstudio

    Participant

    I forgot, you must create the folder and file “members/single/outils/loop-outils.php” or another πŸ™‚

    @justineterniawebcom

    Participant

    @Henry, your code above was helpful. Couldn’t figure out how to loop user-specific posts on profiles. It’s all done now except, do you have any ideas on making pagination work? Googling around query_post() apparently has issues with navigation but usually the issue is displaying the same content on every page.

    In my case it just redirects to a 404 if I try using the pagination. Any ideas?

    This seemed to get the closest in addressing it but doesn’t fix this specific problem: https://wordpress.org/support/topic/page-navigation-038-query_posts

    @justineterniawebcom

    Participant

    Actually solved it by limiting the post count in the loop and then adding this link to the archive of author posts wordpress already innately displays:

    This is the href:

    href="<?php echo get_site_url(); ?>/author/<?php echo the_author_meta( 'user_login' ); ?>

    In case anybody else needs to reference this post like I did.

    @henrywright

    Moderator

    Hi Justin

    The way I would tackle post pagination on BP profile pages would be to use paginate_links

    See:
    https://codex.wordpress.org/Function_Reference/paginate_links

    @emman87

    Participant

    Hi
    I am using Buddyblog to show user posts on profile with the suggested CSS solution to hide the ability to Add New posts. Works great.

    Any CSS suggestions to also hide the Edit, Unpublish and Delete links under each post?

    Emmanuel

    @metadebt

    Participant

    Henry thanks a lot, I was looking for this!

Viewing 25 replies - 26 through 50 (of 51 total)
  • The topic ‘[Resolved] Show posts written by user on profile’ is closed to new replies.
Skip to toolbar