如果用户没有帖子,如何隐藏链接

时间:2016-10-09 12:56:43

标签: php wordpress

如果用户没有帖子,我会尝试隐藏链接。 我尝试了很多片段,但仍然没有工作????

这是我尝试隐藏的链接:<a class="btn btn-success author-link" href="<?php $user_info = get_currentuserinfo(); echo esc_url( get_author_posts_url( $user_info->ID ) ); ?>" rel="author">View all posts</a>

修改 我想我找到了一些东西:

    <?php function count_userposts( $userid ) 
{$args = array(
        'numberposts'   => -1,
        'post_type'     => array( 'post', 'article_type' ),
        'post_status'   => 'publish',
        'author'        => $userid
    );
    $counter_posters = count( get_posts( $args ) ); 
    return $counter_posters; } ?>
<?php if(count_userposts(wp_get_current_user()->ID)) { ?>
<a class="btn btn-success author-link" href="<?php $user_info = get_currentuserinfo(); echo esc_url( get_author_posts_url( $user_info->ID ) ); ?>" rel="author">View all posts</a>
<?php } else { ?>
b
<?php } ?>

提前感谢,

2 个答案:

答案 0 :(得分:0)

以下内容应该有效: -

<?php
if(count_user_posts( get_current_user_id() ) > 0) :
?>
<a class="btn btn-success author-link" href="<?php $user_info = get_currentuserinfo(); echo esc_url( get_author_posts_url( $user_info->ID ) ); ?>" rel="author">View all posts</a>

<?php endif; ?>

答案 1 :(得分:0)

试试这个,这将工作..

<?php
  while ( have_posts() ): the_post();
    // Display post
    if ( have_posts() ): // If this is the last post, the loop will    start over// Do something if this isn't the last post
    endif;
 endwhile;
?>
相关问题