Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Link to authors posts in members_header

  • Profile photo of 3rdaxis
    3rdaxis
    Participant

    @3rdaxis

    Iv spent hours trying all kinds of code trying to get a link to an authors posts displayed in the members_header.php.

    Some code iv tried.

    <a href="<?php echo get_author_posts_url(bp_get_member_user_id()); ?>">Read all posts by <?php echo bp_member_name(); ?></a>

    <p>Other posts by <?php the_author_posts_link(); ?></p>

    <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
    <?php printf( __( 'View all posts by %s <span class="meta-nav"></span>', TEMPLATE_DOMAIN ), get_the_author() ); ?></a>

    many more.

    Can somebody help me display a link for each authors posts that i can place in the members_header.php?

    Thanks

Viewing 5 replies - 1 through 5 (of 5 total)
  • Profile photo of 3rdaxis
    3rdaxis
    Participant

    @3rdaxis

    @henrywright-1 You were able to give me some help before on something similar, Would you be able to help me with the issue in this post?

    Profile photo of Henry
    Henry
    Participant

    @henrywright-1

    Hi @3rdaxis,

    Which author’s posts would you like to display?

    Profile photo of 3rdaxis
    3rdaxis
    Participant

    @3rdaxis

    Thanks for the response, I really just need it to detect the author of the profile the link is going to be on since the site will have many authors. Iv tried a few different ways of getting the authors ID out of the loop but nothing Iv tried has worked besides the code i showed in the original post.

    Iv used this which works in the Author Bio on each post.

    <a href="<?php echo esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ); ?>" rel="author">
    <?php printf( __( 'View all posts by %s <span class="meta-nav"></span>', TEMPLATE_DOMAIN ), get_the_author() ); ?></a>
    Profile photo of Henry
    Henry
    Participant

    @henrywright-1

    @3rdaxis

    When viewing a member’s profile page, you can use bp_displayed_user_id() to get the ID of the member. This will then let you display a list of their posts or their latest post. e.g.

    $my_query = new WP_Query( 'author=' . bp_displayed_user_id() );
    
    if ( $my_query->have_posts() ) {
    	while ( $my_query->have_posts() ) {
    		$my_query->the_post();
    		echo '<li>' . get_the_title() . '</li>';
    	}
    } else {
    	// no posts found
    }
    wp_reset_postdata();

    But then note, when you navigate away from the member’s profile page, posts will no longer be displayed due to bp_displayed_user_id() no longer holding a value. To me, this would make sense as if you were viewing the Privacy Policy or About Us pages (for example) you wouldn’t want a member’s posts to show up.

    Profile photo of 3rdaxis
    3rdaxis
    Participant

    @3rdaxis

    Thanks Henry, from the code you gave me, i was able to put this one together to display a link to a page of the authors posts with this line of code and it works perfect.

    <a href="<?php echo esc_url( get_author_posts_url( bp_displayed_user_id() ) ); ?>" rel="author">Read all posts by <?php echo bp_displayed_user_fullname(); ?></a>

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] Link to authors posts in members_header’ is closed to new replies.
Skip to toolbar