• Resolved hellorichelle

    (@hellorichelle)


    Hello,

    I’m customizing my own template for the first time and changed everything from the RedStamp template (Big mistake now I look back) but so far I find every answer I need in support of WordPress except for this one:

    I’ve added this to show only 3 posts in my “news” feed

    <?php query_posts(‘&posts_per_page=3’); ?>

    And I wrote 5 test-posts, now this code is working but I can’t get to my “previous page” where the other 2 articles may be found.

    I tried to find it in my own browser by adding /page/2 (=404 error)
    or /2 or index.php/page/2 and so on, but I couldnt find it myself.

    So I went tried a couple of other codings people suggested but nothing got me to my other 2 posts.

    The only thing that got me closest is:

    <?php
    				$pagelist = get_pages('sort_column=menu_order&sort_order=asc');
    				$pages = array();
    				foreach ($pagelist as $page) {
      				 $pages[] += $page->ID;
    				}
    
    				$current = array_search(get_the_ID(), $pages);
    				$prevID = $pages[$current-1];
    				$nextID = $pages[$current+1];
    				?>
    
    				<div class="navigation">
    					<?php if (!empty($prevID)) { ?>
    						<div class="alignleft">
    							<a>"
      							title="<?php echo get_the_title($prevID); ?>">Previous</a>
    						</div>
    					<?php }
    					if (!empty($nextID)) { ?>
    					<div class="alignright">
    						<a>"
      							title="<?php echo get_the_title($prevID); ?>">Previous</a>
    						<a>"
     						title="<?php echo get_the_title($nextID); ?>">Next</a>
    						<!-- lol had to put both in "alignright because I still need to fix the css -->
    					</div>
    					<?php } ?>
    				</div><!-- .navigation -->

    But what happens is that this brings me to the third article on the page, not the (previous) index-view.. as if that page don’t exist. You can check it here:

    https://www.huismanadvies.com/nieuws/
    (ps. everything is still much under construction)

    How can I get my previous page working? or how can I find my previous page?

    I’m a student webdesigner, writing a wordpress template is all new to me, but I can read and understand what is said most of the times. But I dont understand any of the navigationsystem so far……

    Thanks for reading, I hope you can help?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Is it an archive page? or a blog post page? or a custom page that you create?

    Working with custom navigation on WordPress has a few ways based on the template file that you put it.

    If it is an archive page, you shouldn’t write query_posts(); Just change it in the reading section under the Setting tab.

    If it is a custom page or you need a custom loop that you can do the query as you like, you need to handle navigation by yourself.

    Checkout this link, it will help you to work with custom pagination.
    https://weblogtoolscollection.com/archives/2008/04/19/paging-and-custom-wordpress-loops/

    Thread Starter hellorichelle

    (@hellorichelle)

    Hello Gidd,

    Thank you for responding;
    The page is index.php and there was already a navigationcode in (but it didn’t work)
    The code that was in it was:

    <div class="navigation">
    					<div class="navigation">
    						<ul>
    							<li class="alignleft"><?php// next_posts_link('Previous Page') ?></li>
    							<li class="alignright"><?php// previous_posts_link('Next Page') ?></li>
    						</ul>
    					</div>
    				</div>

    But this lead me to a 404 error (in the browser it led me to https://www.huismanadvies.com/nieuws/page/2/ )

    I don’t quite understand the loops. I tried to use the one in the link you showed me, but eventually this code also led me to
    https://www.huismanadvies.com/nieuws/page/2/ and so an error 404 ):

    Thread Starter hellorichelle

    (@hellorichelle)

    I AM THE BIGGEST IDIOT EVER.

    Solution: I changed in my Settings> Reading
    to show 3 posts instead of 5.

    Makes sense cause itll make page 2 “exist” due the other 2 posts that arent bein shown on page 1, which had been shown “invisibly”

    Thanks for all the efforts

    This case is solved!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to get "previous page" (It doesn't exist)’ is closed to new replies.