[英]How to hide a link if the user has no posts
如果用戶沒有帖子,我會嘗試隱藏鏈接。 我嘗試了很多片段,但仍然無法正常工作????
這是我試圖隱藏的鏈接: <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;
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.