首页 文章

如何在buddypress中的成员 Profiles 页面上显示帖子

提问于
浏览
0

我正在使用最新的wordpress和buddypress版本 . 我想在作者 Profiles 页面上显示作者的帖子,以实现这一目标 . 我将members / single / profile.php复制到mytheme / buddypress / members / single / profile.php

然后我添加此代码片段

do_action('bp_after_profile_content')

<?php 
$args = array( 'author' => bp_displayed_user_id(),
                'post_type' => 'post'
        );
query_posts( $args );
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', $theme_options['post_layout'] );
endwhile; else:
echo ('no posts found so do something less amazing');
endif;
?>

我得到的结果是每个帖子的重复,第一个是exceprt,然后是完整的帖子 . 我只想在会员资料页面上显示每个帖子的摘录 . 请看这个 . http://bit.ly/1mEbj0G

我正在使用最新的wordpress和buddypress版本 .

1 回答

  • 1

    如果是这是一个 Profiles 页面,那么你会想把它放在这里 .

    /wp-content/themes/YOURTHEME/buddypress/members/single/index.php
    

    这是我正在使用的精简版 .

    <?php 
    $authorID = bp_displayed_user_id();
    $args = array( 'author' => $authorID, 'orderby' => 'date', 'order' => 'ASC', 'posts_per_page' => 10 );
    $loop = new WP_Query( $args );
    if ($loop->have_posts() ) :
    ?><!-- bgn if user has posts -->
    
    <!-- bgn posts by this author -->
    <?php 
    while ($loop->have_posts() ) : $loop->the_post();
    ?>
    
    <!-- your html -->
    
    <?php endwhile; ?>
    <!-- end lessons/posts by this author -->
    
    
    <?php else : ?><!-- else show nothing -->
    
    <!-- nothing -->
    
    <?php endif; ?><!-- end if user has posts -->
    
    <?php wp_reset_postdata(); ?>
    
    <!-- end posts by this author -->
    

相关问题