WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Author page pagination (15 posts)

  1. wspencer
    Member
    Posted 11 months ago #

    Not sure what's going on here but my author page pagination is giving me quite a headache. It works with some authors but others, it doesn't. For the authors it doesn't work for, it's giving me a 404 error on anything other than the first page.

    I've tried it with query_posts and setting a new WP_Query. I'm scratching my head on this one. Any help is appreciated. Thanks!

    <?php $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    
    $args = array( 'author_name' => $curauth->user_nicename,
    		'posts_per_page' => 10,
    		'paged' => $paged,
    		'post_type' => array('post','video'));
    
    query_posts( $args ); ?>
  2. Sunder Deep Dasna
    Member
    Posted 11 months ago #

    query_posts() or WP_Query should not be used in the author.php.
    Pagination is shown in the author.php by using the plugin WP PAge Navi or any other plugin.

    Hopefully this will work for you.

  3. wspencer
    Member
    Posted 11 months ago #

    I'm using WP Page Navi. Pagination shows but the links go to 404 errors.

    Care to provide me with a working example? Thanks

  4. Jose Castaneda
    Member
    Posted 11 months ago #

    I have to ask the question of what is it you are trying to do exactly? Are you trying to get a list of all the authors? All the posts by said author?

  5. wspencer
    Member
    Posted 11 months ago #

    All the posts by the particular author. I'm just unsure why it's working properly for some authors but not all the authors. Clearly I'm doing something wrong.

  6. Jose Castaneda
    Member
    Posted 11 months ago #

    If your theme has a author.php file then that would be the file to look for and in as Sunder Deep Dasna said.

    With that being said I would say take a look at how the default themes handle the author. I want to say they use: rewind_posts() but not sure if that is the function. The way the author page works is a little strange since it uses the first post to figure out what author and then you use rewind_posts to create the "loop" of posts for that author.

  7. wspencer
    Member
    Posted 11 months ago #

    I'll take a look but I think I did something similar by killing the default query through wp_reset_postdata() and wp_reset_query(), and I still had issues. But those might have ruined pagination since they were at the start of the template file. Crap....

  8. Sunder Deep Dasna
    Member
    Posted 11 months ago #

    Are you using author.php?

    Are you using Query_posts() in author.php?

    How do you use the loop in your code?

    Please show your code of snippet of loop and pagination.

  9. wspencer
    Member
    Posted 11 months ago #

    Yes, I'm using author.php and if you look at the code snippet I posted above, you'll see the query arguments. Pagination is controlled by WP Page-Navi plugin.

  10. Sunder Deep Dasna
    Member
    Posted 11 months ago #

    If you are using author.php then you don't need to use this code

    <?php $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    
    $args = array( 'author_name' => $curauth->user_nicename,
    		'posts_per_page' => 10,
    		'paged' => $paged,
    		'post_type' => array('post','video'));
    
    query_posts( $args ); ?>

    Only Use this code and remove the query posts:

    if(have_posts()) : while( have_posts() ): the_post();
     your loop code
    endwhile;
     wp_pagenavi();
     endif;
  11. wspencer
    Member
    Posted 11 months ago #

    How do I make sure it includes custom post types without passing arguments?

  12. acrane
    Member
    Posted 11 months ago #

    I agree. you need to get the CPT in there somehow. I was able to get the pagination to work for my 2 authors and my page template queries by dropping the "if has_posts" But one of the authors gets a 404 after the second page. my code below. Almost there... looking for the same solution :)

    <?php
    $author_details = $wp_query->get_queried_object();
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $wp_query->query(array(
    	'post_type'=> array('blog', 'filmmaking', 'biology'),
    	'paged' => $paged,
    	'posts_per_page' => 2,
    ));
    
    while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    <h2><a href="<?php the_permalink(); ?>">author <?php the_title(); ?></a></h2>
    <?php endwhile;  wp_reset_postdata(); ?>
  13. wspencer
    Member
    Posted 11 months ago #

    Yep. Sounds like the same issue I'm having. Some authors it works....some authors, it doesn't.

  14. acrane
    Member
    Posted 11 months ago #

    Ok, please double check, but I think I got it all working.

    First, i put this function into my functions file from this thread: (I'm working with 3 CPT)
    http://wordpress.org/support/topic/modifying-author-archive-to-include-custom-post-type-and-pagination?replies=4

    function custom_post_author_archive( &$query )
    {
        if ( $query->is_author )
            $query->set( 'post_type', array( 'filmmaking', 'biology', 'blog' ));
        remove_action( 'pre_get_posts', 'custom_post_author_archive' ); // run once!
    }
    add_action( 'pre_get_posts', 'custom_post_author_archive' );

    Then, my Author.php file looks like this where I add, "author" to the query arguments in a dynamic way.

    <?php
    /**
     * Template for Author
     */
    get_header(); ?>
    
    <div id="page-left">
    
    <?php if ( have_posts() ) : ?>
    
    <?php the_post(); ?>
    <!-- you can put Author header here -->
    <?php  rewind_posts(); //then rewind ?>
    
    <?php
    $author_details = $wp_query->get_queried_object();
    $curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
    $temp = $wp_query;
    $wp_query = null;
    $wp_query = new WP_Query();
    $wp_query->query(array(
    	'post_type'=> array('blog', 'filmmaking', 'biology' ),
    	'paged' => $paged,
    	'posts_per_page' => 2,
    	'author' => $author
    ));
    
    	while ($wp_query->have_posts()) : $wp_query->the_post(); ?>
    
    <h2><a href="<?php the_permalink(); ?>">author <?php the_title(); ?></a></h2>
    
    <?php endwhile; endif; wp_reset_postdata(); ?>
    
    <?php untamed_pagi(); ?>
    
    </div><!-- page left -->
    <?php get_footer(); ?>

    Working for me. Hope this helps you.

  15. wspencer
    Member
    Posted 11 months ago #

    Thanks acrane. That did work for me!

Reply

You must log in to post.

About this Topic