Title: Custom Theme Problem
Last modified: August 18, 2016

---

# Custom Theme Problem

 *  [hbalagh](https://wordpress.org/support/users/hbalagh/)
 * (@hbalagh)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/custom-theme-problem/)
 * I just noticed that when you you go to the bottom of my blog and hit the link
   to view previous post it will take you to
    [http://www.heathersblog.com/page/2/](http://www.heathersblog.com/page/2/)
   like it’s supposed too but still shows the most recent post (the main page)
 * I have this in the template for the nav at the bottom…
 * i am wondering am i forgetting a piece of code that needs to be in the template
   🙂 thanks
    `<div class="alignleft"><?php posts_nav_link('','','&laquo; Previous
   Entries') ?></div>`
 *  <div class="alignright"><?php posts_nav_link('','Next Entries &raquo;','') ?
   ></div>

Viewing 8 replies - 1 through 8 (of 8 total)

 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324383)
 * This is a custom theme…so in your theme’s index.php, is [The Loop](http://codex.wordpress.org/The_Loop)
   being initialized by [query_posts()](http://codex.wordpress.org/Template_Tags/query_posts)
   for some reason?
 *  Thread Starter [hbalagh](https://wordpress.org/support/users/hbalagh/)
 * (@hbalagh)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324386)
 * here is my index file
 * [http://pastebin.com/520074](http://pastebin.com/520074)
 *  [Kafkaesqui](https://wordpress.org/support/users/kafkaesqui/)
 * (@kafkaesqui)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324395)
 * Aha!
 * `<?php
    if (is_home()) { query_posts("cat=-3"); } ?>
 * That’s the culprit. But not to worry, as there’s a solution:
 * `<?php
    if (is_home()) { $paged = (get_query_var('paged')) ? get_query_var('paged'):
   1; query_posts("cat=-3&paged=$paged"); } ?>
 * Let me explain what I’ve added, and why.
 * query_posts() is a powerful function, but in this situation it has a flaw: it
   overrides nearly everything in the standard posts object query, including what
   the paged offset is. To get proper pagination with query_posts() we need to recreate
   it through the ‘paged’ parameter or query. Best way to do this is to _ask_ WordPress
   for the “page” we happen to be on, and use that as our ‘paged’ value.
 * The `$paged =` line above uses what’s called a ternary operator to test whether
   the ‘paged’ query variable is available. If it is, $paged receives its value.
   If it isn’t, we assume we’re on the first page and assign it ‘1’. Then we tell
   query_posts() what page we’re on with the addition of `&paged=$paged`.
 *  Thread Starter [hbalagh](https://wordpress.org/support/users/hbalagh/)
 * (@hbalagh)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324401)
 * Thank you so much 🙂 it works like a charm now, and thanks for taking the time
   to explain it in detail
 *  [cow6oy](https://wordpress.org/support/users/cow6oy/)
 * (@cow6oy)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324734)
 * I would like to implement the above snippet of code into an archive page which
   has an additional decorative loop with 3 posts of category 14.
 * What should the last line look like?
 * ‘
    <?php if (is_archive()) { $paged = (get_query_var(‘paged’)) ? get_query_var(‘
   paged’) : 1; query_posts(cat=-14&paged=$paged”); // how should this look like?}?
   > ‘ The code above does not work. My archive of category 9 contains only one 
   post. But with this code a lot of other posts (it seems to be all of them) are
   shown.
 * Hope this pastebin doesn’t expire as fast as the previous one: [http://pastebin.com/527946](http://pastebin.com/527946)
 *  [cow6oy](https://wordpress.org/support/users/cow6oy/)
 * (@cow6oy)
 * [20 years, 4 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324735)
 * As a sidemark: I wanted to hide my news loop on previous pages so news loop would
   only show up once on the home page. This is the code that worked for me:
 * `<!-- START: if URL not paged, show news, else hide news -->
    <?php if (!isset(
   $_GET['paged']) && empty($_GET['paged'])) { ?>  <h2 class="news_head">The News
   </h2> <?php include_once( 'my_loop_news.inc.php' ); ?> <?php } ?> <!-- END: if
   URL not paged, show news, else hide news-->
 *  [madinkbeard](https://wordpress.org/support/users/madinkbeard/)
 * (@madinkbeard)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324793)
 * Thanks so much, Kafkaesqui! This problem has been giving me a headache and your
   code solved it perfectly.
 *  [Ryan Fitzer](https://wordpress.org/support/users/ryanfitzer/)
 * (@ryanfitzer)
 * [19 years, 8 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324796)
 * Kafkaesqui, where exactly should your solution be placed? I’ve put it in the 
   loop as follows with no success:
 * `<?php endwhile; ?>
    <?php if (is_home()) { $paged = (get_query_var('paged'))?
   get_query_var('paged') : 1; query_posts("cat=-6&paged=$paged"); } ?> <?php else:?
   >
 * I’m assuming that `cat=-6' will exclude the cat. Any advice would be appreciated.
   BTW my loop starts out as follows:
    
   <?php query_posts(‘cat=1,2,3,4,5,7&showposts
   =1’); ?>
    <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post();?
   >`

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Custom Theme Problem’ is closed to new replies.

 * 8 replies
 * 5 participants
 * Last reply from: [Ryan Fitzer](https://wordpress.org/support/users/ryanfitzer/)
 * Last activity: [19 years, 8 months ago](https://wordpress.org/support/topic/custom-theme-problem/#post-324796)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
