Php 如果用户没有帖子,如何隐藏链接
如果用户没有帖子,我会尝试隐藏链接。 我尝试了很多片段,但仍然不起作用 下面是我试图隐藏的链接:Php 如果用户没有帖子,如何隐藏链接,php,wordpress,Php,Wordpress,如果用户没有帖子,我会尝试隐藏链接。 我尝试了很多片段,但仍然不起作用 下面是我试图隐藏的链接: 编辑: 我想我发现了一些东西: <?php function count_userposts( $userid ) {$args = array( 'numberposts' => -1, 'post_type' => array( 'post', 'article_type' ), 'post_status'
编辑:
我想我发现了一些东西:
<?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 } ?>
B
提前感谢,以下功能应该可以正常工作:-
<?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;
?>
U需要添加更多关于帖子的代码。我想if(count($allpost)>0){//在这里写代码}
但问题是,你在哪里定义post并执行if($user\u post>0)
谢谢,我想我找到了隐藏链接的方法!我不知道这是否是最好的解决方案,但它是有效的!