WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Show Author Count with link to the Author's post page (6 posts)

  1. SebastienRoche
    Member
    Posted 4 years ago #

    Hi,

    I am trying to show the number of posts written by a particular Author linking to the Author's page.

    I call the tag:

    <?php the_author_posts(); ?>

    I would like to have it as a link to http://mydomain.com/?author=x. For that particular author. A bit like the tag:

    <?php the_author_posts_link(); ?>

    Thank you for your help.
    Sebastien.

  2. MichaelH
    Member
    Posted 4 years ago #

    Assuming you are in the loop:

    <?php
    $userposts = get_posts('showposts=-1&author='.$post->post_author);
    if ($userposts) {
      $count=count($userposts);
      echo '<p>number of author posts: ' . $count . '</p>';
    }
    ?>
  3. Mark / t31os
    Moderator
    Posted 4 years ago #

    I would like to have it as a link to http://mydomain.com/?author=x. For that particular author. A bit like the tag:

    Isn't that exactly what the_author_posts_link does?
    http://codex.wordpress.org/Template_Tags/the_author_posts_link

    I think you're asking how to do this outside the loop aren't you? , which is why neither of the above functions are suited in this, would that be correct?

  4. SebastienRoche
    Member
    Posted 4 years ago #

    Thank you so much for the answer.

    @MichaelH: The Tag <?php the_author_posts(); ?> does already the job I was looking for. The code you gave me does the same -1 post. But thank you for the answer.

    @t31os_: The Tag <?php the_author_posts_link(); ?> gives you the author's name with a link <a> to the page http://mydomain.com/?author=x ; x being the ID of the author of the article. What I am looking for is to have the same link <a> when using the Tag <?php the_author_posts(); ?>. I don't know how to call the author's ID to create the hyperlink to its posts list.

    Thank you again for your help.
    Sebastien.

  5. Mark / t31os
    Moderator
    Posted 4 years ago #

    How about something like this then.

    <a href="<?php echo get_author_posts_url( $post->post_author ); ?>"><?php the_author(); ?> <?php the_author_posts(); ?></a>

    .. assuming of course that you're using that in the loop..

    That will give a link to the author posts, with the text of the author's name and a numeric value beside it indicating how many posts they've made.

    Is that what you're after?

  6. SebastienRoche
    Member
    Posted 4 years ago #

    This is exactly what I was looking for!

    The final code I used is <a href="<?php echo get_author_posts_url( $post->post_author ); ?>"><?php the_author_posts(); ?></a> since I just wanted the number of post as a link.

    Thank you again for your help.
    Sebastien.

Topic Closed

This topic has been closed to new replies.

About this Topic