• I’ve repurposed my homepage.php to display a grid of images, each linking to their relevant post. I’ve then used homepage.php as a “Page” template, to give it a fixed URL. It looks great for my needs, also serving as a hacky archive, however page navigation no longer works.

    I’d like to find a simple next/previous page OR page numbering solution. Any help would be much appreciated, (and no plugins please).

    Here’s my code (minus any navigation). Thank you!!

    <?php
    //Template Name: Home
    get_header()
    ?>
    <div class=”container”>
    <header>
    <!–<h1><?php echo get_option(‘tiny_head_title’) ?></h1> –>
    <!–<p><?php echo get_option(‘tiny_head_description’) ?></p>–>
    </header>

    <?php $paged = get_query_var(‘page’);??>

    <?php $home = new WP_Query(array(‘post_type’=> ‘post’, ‘posts_per_page’ =>8, ‘paged’ => $paged)); ?>

    <?php if($home->have_posts()): ?>

    <div class=”posts”>
    <?php while($home->have_posts()) : $home->the_post(); ?>
    <div class=”archivemother”><div class=”archivethumb”><?php agentwp_print_post_title(); ?></div></div>
    <!– <?php the_excerpt() ?> –>

    <?php endwhile; ?>
    </div>
    <?php endif; ?>
    </div>
    <?php get_footer()?>

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Right, custom queries break the default pagination. When you use custom queries, you are forced to manage your own pagination. Many people have tried to trick the default WP pagination into thinking the custom query is the default main query. I’ve yet to see a satisfactory solution to this approach.

    Developing your own pagination is not that complicated. As long as your script knows what page it’s on, where the user wants to go, and how many posts per page, it’s trivial to come up with the proper offset argument for the next (or prev) query. Yes, using offset screws up paged and breaks pagination. News flash, pagination is already broken! ??

    The ideal approach IMO is to not make a custom main query in the first place. Instead of ignoring the default main query and going it alone, use the ‘pre_get_posts’ action to mold the main query to meet your needs. This is also more efficient because you are not discarding the main query in favor of a custom query. More on this approach in Plugin API/Action Reference/pre get posts.

Viewing 1 replies (of 1 total)
  • The topic ‘Homepage.php Navigation help for (working) thumbnail listing’ is closed to new replies.