Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#49773 new enhancement

Navigating through list of posts on single.php is not functioning

Reported by: 1bjk903's profile 1BJK903 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 5.5
Component: Posts, Post Types Keywords: needs-testing 2nd-opinion reporter-feedback
Focuses: template Cc:

Description

Wordpress is fantastic, but there are some flaws (at least from my perspective). I don't know if this can be classified as a bug or an enhancement, but WordPress expects that (single) pages could contain archive listings and might require pagination, yet single posts do not expected to have archive listings which is causing this issue. Instead of taking the page-slug/page/#/, it should take the post-slug/#/ when using the pagination in single.php.

What's happening is that the page # request portion is ignored and $paged will always be 1, and the “wrong” URL is rewritten to the “correct” one. Taking the $paged value from the main query and use it in a custom query often is problematic.

So, it does not allow us to add navigate through a list of posts in single.php. When using e.g. this snippet:

    <div class="test">...</div>
    			<ul class="pagination">
				<li class="page-item"><?php previous_posts_link('&laquo; Previous') ?></li>
				<li class="page-item"><?php next_posts_link('Next &raquo;') ?></li>
			</ul>

It will only spit out the HTML elements, but not the buttons, as there is nothing to show.

Another example:

<?php
                <?php 
                // wp query
                $wp_query = new WP_Query(  array( 'posts_per_page' => 25,
                                                                                   'paged' => $paged,
                                                                                        ) ); 
                $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;

                if ( $wp_query->have_posts() ) : 
                ?>
                        <!-- pagination here -->
                        <!-- the loop -->
                        <?php 
                        while ( $wp_query->have_posts() ) : $wp_query->the_post(); 
                        ?>                                                      
                                <li id="test" data-href="<?php $blink = get_the_permalink(); ;?>">
                                        <div>
                                                <a id="test" href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                        </div>
                                </li>
                        <?php endwhile; ?>

Nothing works. Best case scenario is that it adds a page, but you then get the following: websiteURL/post-url/page/number

And of course, that also does not work and therefore you can't scroll through posts as you like.

Can we get this checked and hopefully fixed, please? I am desperately waiting for this, and many more are like me (Stackoverflow is filled with these questions).

Change History (1)

#1 in reply to: ↑ description @SergeyBiryukov
4 years ago

  • Focuses ui accessibility removed
  • Keywords reporter-feedback added; needs-patch needs-dev-note removed

Hi there, welcome to WordPress Trac! Thanks for the report.

Instead of taking the page-slug/page/#/, it should take the post-slug/#/ when using the pagination in single.php.

Just to clarify, these are not the same thing:

  • /page/#/ corresponds to the paged query variable that is used for various archives.
  • /#/ corresponds to the page query variable that is used for post content separated with <!--nextpage--> tag in combination with wp_link_pages() in single post template.

I know this might be confusing.

Another example:

<?php
<?php 
// wp query
$wp_query = new WP_Query(  array( 'posts_per_page' => 25,
                                                                   'paged' => $paged,
                                                                        ) ); 
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
...

You're using the $paged variable before it's defined. You should define it before $wp_query, not after.

So far, I'm having trouble reproducing the issues. Сould you provide the steps to reproduce the issue on a clean install?

Note: See TracTickets for help on using tickets.