Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to create a post tab in profil without double output


  • ronsenbln
    Participant

    @ronsenbln

    Hi, i am new with buddypress and wordpress to. Now i will create a community and use both. I like to show the posts of a user in his profil and not in an author page.

    I found that i can create a new tab and this works. The post will show. But i cant make it work without a double output.

    Here is my code:

    functions.php

    // Buddy Press Funktionen
    
    function my_redirect_canonical($redirect_url, $requested_url) {
     // If on a BuddyPress page, just go to the requested URL: no redirects!
     if ( bp_is_members_component() || bp_is_user() ) {
       return $requested_url;
     } else {
       return $redirect_url;
     }
    }
    add_filter('redirect_canonical', 'my_redirect_canonical', 10, 2);
    
    // Buddy Press Funktionen Posts im Profil
    
    add_action( 'bp_setup_nav', 'add_profileposts_tab', 100 );
    function add_profileposts_tab() {
    global $bp;
    bp_core_new_nav_item( array(
    'name' => 'News',
    'slug' => 'posts',
    'screen_function' => 'bp_postsonprofile',
    'default_subnav_slug' => 'News', 
    'position' => 250
    )
    );
    }
    // 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() {
    query_posts( 'author=' . bp_displayed_user_id() );
    	if ( have_posts() ) :
    	get_template_part( 'author-user' );
    	else:?>
    	<div id="message" class="info">
    		<p><?php bp_displayed_user_username(); ?> hat noch nix geschrieben! </p>
    	</div>
        <?php endif; ?>    <?php
    
    }
    
    //POSTS ON PROFILE ENDS HERE

    author-posts.php

    <ul>
    		<!-- Loop -->
    		<?php while(have_posts()) : the_post(); ?>
    <?php the_post_thumbnail( 'teaser' ); ?>
    			<h2>
    				<a href="<?php esc_url(the_permalink()); ?>"><?php the_title(); ?></a>
    			</h2>
    			Erstellt am <?php echo get_the_date(); ?> 
    <div class="tags"><?php the_tags('','',''); ?></div>
    			<div class="content-inner"><?php the_excerpt(); ?></div>
    
    		<?php endwhile; ?>
    	
    		<!-- Paginierung -->
    		<p><?php posts_nav_link(); ?></p>
    
    <!-- End Loop -->
    
        </ul>
    

    This code shows the author posts in the right way. But under the output i like is an output that i dont like to have. It shows the post twice. Any idea for this problem? Best

Viewing 1 replies (of 1 total)

  • ronsenbln
    Participant

    @ronsenbln

    No one? I like to make the same with custom post types and comments, but first i like to have a working soloution. I cant find a howto and no plugin to do this. Is there no way to have this little function working without double output?

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar