如果用户没有帖子,我尝试隐藏链接。我尝试了很多片段,但仍然不工作????
这是我试图隐藏的链接:<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 } ?>
提前致谢
下面应该可以工作:-
<?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; ?>
试试这个,这就行了。
<?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;
?>