• Hello!

    I have an issue which I need to sort asap for a client.

    When I activate s2members, the pagination of the posts in homepage is not working.

    I have tried different plugins and also the default previous-next navigation, and they all work normally with s2members deactivated. as well, they work fine if the page is NOT the homepage (see this test page which uses the same template as the home: https://paulthetall.com/test/ )

    basically if you are in the homepage, when you click on a page number, you’ll be redirected to the home-url, rather than to an url which passes the pagination vars.

    by instance, if you go here (or click on the number in the pagination):
    https://paulthetall.com/page/2/

    you’ll be redirected to the homepage url ( https://paulthetall.com/ ) and no pagination var will be passed to the query..

    the welcome page and members option page are set to be pages which are NOT the same page as the homepage, so this is not the cause.

    I’ve found a few other old topics about this very same issue, but none of them had reached a solution.

    I hope you’ll be able to help me as I have a lot of pressure from my clients and I don’t know how to deal with this bug..

    Thanx!

    https://www.ads-software.com/plugins/s2member/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Are you using absolute or relative links?

    I have found that I sometimes get a “page not found” message if I use relative links on the home page, whereas using absolute links instead avoids the problem.

    Thread Starter piccart

    (@piccart)

    Hi there!

    Thanks for your reply.

    my pagination plugin uses url like this:
    https://paulthetall.com/page/2/

    the problem is that if you go to that link, or if you click on the pagination’s numbers at the bottom of the homepage, you’ll be redirected to the main root https://paulthetall.com/
    and so the vars about the $paged are not passed to the main query, which loads the first page again. I am not getting errors, nor 404, it just redirect to the website main root url..

    if I deactivate s2member, everything works fine. and actually if you are in a page which is not the homepage, the pagination works fine even with s2member activated..

    OK, so you are using absolute links already.

    The thing that strikes me about what you say is that s2member does not protect the home page. So are all the paginated pages open for public viewing? They will all need to be open to the public for your pagination to work.

    If they are all open to the public, then I think you have a plugin (or theme) conflict with s2member (and it isn’t necessarily the pagination plugin that’s the culprit).

    Thread Starter piccart

    (@piccart)

    do you mean that if there is one post which is not open to the public, the pagination won’t work at all rather than just don’t display that post in the listing??

    anyway, the default wordpress navigation with previous and next links, is not working as well, so I wouldn’t say the issue is related to the theme.

    anyway, this is the piece of code which handle the pagination and the query in that page-template:

    global $more; $more = 0; // Enable 'more tag' for this page
                // Begin main posts' loop stuff here
                //adhere to paging rules
                if ( get_query_var('paged') ) {
                    $paged = get_query_var('paged');
                } elseif ( get_query_var('page') ) { // applies when this page template is used as a static homepage in WP3+
                    $paged = get_query_var('page');
                } else {
                    $paged = 1;
                }
    
                if ( $udesign_options['exclude_portfolio_from_blog'] == 'yes' ) {
                    // get the portfolio categories to be excluded from the Blog section
                    global $portfolio_cats_with_minus;
                    $query_string = "cat=$portfolio_cats_with_minus&paged=".$paged;
                } else {
                    $query_string = "paged=$paged";
                }
    
                query_posts( $query_string );

    I noticed on your website that you got this issue fixed. How did you do it? I’m facing the same issue right now and there are a lot of postings about this issue but no definite answers.

    Thread Starter piccart

    (@piccart)

    hello!
    I had forgot about this topic..
    so, basically I’ve realized that this is a bug which has no solution (or at least it didn’t when I was looking at it), so I’ve figured out a way to going around it.

    basically I’ve created a clone of the homepage (called NEWS), which looks the very same and displays a loop of all posts at the same as the home did (in that case I had a page template for “blog” and I applied it, but it’s not too tricky to create one if you don’t have it).

    anyway, as I said before, the pagination works perfectly in pages other than home, so I’ve just builded up manually the pagination buttons for the home, making it so that the links points to this clone page rather than the home itself, passing the value of the page number that it should be displayed when landing. so basically after the first click on a navigation link from the home, you actually land and then browse pages from this clone page. ??

    note: this hack needs to have the plugin wp pagenavi installed, you can get it here: https://www.ads-software.com/plugins/wp-pagenavi/

    so, after you’ll create the clone page, you should copy this code on your page.php template. I’ve commented it extensively, so you should be fine

    <?php
    /**** HACK TO GO AROUND THE S2MEMBERS BUG WHICH BREAKS PAGINATION LINKS IN HOMEPAGE ******/
    /* code by A Piccart
    /* author ref: https://affordable-web-developer.com
    /*
    /* create a clone page of your home (in this case called NEWS, if you name it differently, change it through the code)
    /* add this code below your posts loop in home template file, or in page.php if you have only that template file for pages.
    /*
    /* note: this hack requires the plugin page-navi to be activated
    /* you can get it from here: https://www.ads-software.com/plugins/wp-pagenavi/
    */
    ?>
    
    <?php // if the page is not the home, call the normal pagination from the plugin ( you can strip this bit if you are pasting this in a home-template file)
    if (is_home()){ // if this conditional is still displaying the real navigation in home, try using if (is_front_page()) {
    	wp_pagenavi();
    }
    else { // if it's the home, print our custom made navigation (if you are pasting this in a home-template file, start from here)
    	?>
    
    	<?
    	// get the number of post in the main query
    	$total_posts = $wp_query->found_posts;
    	// get the number of posts per page set in the options
    	$posts_per_page = get_option('posts_per_page');
    
    	// calculate the number of total pages
    	$tot_pages = round($total_posts / $posts_per_page) ; // round the result to be an integer
    
    	// set a var for a counter (since we are in the first page, the counter starts from there)
    	$page_count = 1;
    	?>
        <!-- print the beginning of the page-navigator -->
        <div class='wp-pagenavi'>
            <span class='pages'>Page 1 of <?php echo $tot_pages; ?></span>
            <span class='current'>1</span> <!-- as this code will be in home, the current page will of course be the 1st -->
    
            <?php // foreach page till the counter is less than 10 (the number of pages we want in the navigation) , print the number with the link.
            while ($page_count <= 10 ){
                // carry on only if the total pages are actually at least the same amount of the current number
                if ($page_count <= $tot_pages){
                    // increment the counter for the next page
                    $page_count++ ;
                ?>
                <!-- this will print a number box which links to our news page passing the currently looped number to the page navigation of it -->
                <a class="page larger" href="<?php echo home_url(); ?>/news/page/<?php echo $page_count; ?>/"><?php echo $page_count; ?></a>
    
                <?php
                }
            } // we can close the nuber boxes loop 
    
            // if there are still pages, print the suspension dots
            if ($tot_pages >= $page_count ){ // consider that after printing the 10th box, the page counter is actually 11
                ?>
                <span class='extend'>...</span>
                <?
            } ?>
    
            <!-- print the NEXT button which in the homepage will be page 2 -->
            <a class="nextpostslink" href="<?php echo home_url(); ?>/news/page/2/">?</a>
    
            <?php // again, print the last button only if the pages were actually more than 10
            if ($tot_pages >= $page_count ){
                ?>
                <!-- print the link to the last page -->
                <a class="last" href="https://paulthetall.com/news/page/<?php echo $tot_pages; ?>/">Last ?</a>
                <?
            } ?>    
    
        <!-- close the pagination div -->
        </div>
    
    <?php // close our pagination conditional (strip this if you are pasting this in a home-template file)
    } ?>

    I actually rewrited this now, as that site is not mine and I have not access to it at the moment. so I haven’t tested it but it should work. let me know how it goes! ??

    cheers!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[S2Members] Pagination not working in Homepage’ is closed to new replies.