I am experimenting with custom loops and following the tutorial of the illustrious Chip Bennett, and I actually got everything to work on index.php!
...
Up to, that is, page 3.
Everything works lovely when I go to page 2. On any higher page, it's white screen of death time.
To my eye, my code is practically identical to the one provided in the link, but for completeness:
$hero_args = array(
"posts_per_page" => "1",
);
$hero_args['paged'] = get_query_var( 'paged' )
? get_query_var( 'paged' )
: 1;
$heroPost = new WP_Query($hero_args);
<div class = "blog_content_wrap">
<div class = "hero_blog">
<?php $temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $heroPost;?>
<?php if ($heroPost -> have_posts()): ?>
Query contains something
<?php while ($heroPost -> have_posts()):
$heroPost -> the_post();
the_title();?>
<?php endwhile;
?>
<?php else:?>
No posts found, sucker
<?php endif;
wp_reset_postdata();
print_r ($hero_args['paged']);
previous_posts_link( 'Older Posts' );
next_posts_link( 'Newer Posts', $heroPost->max_num_pages );
the_posts_pagination();
$wp_query = NULL;
$wp_query = $temp_query;
?>
</div>
I have a sneaking suspicion it has to do with the max_num_pages? But I'm not sure at all. It's a PHP error, but I have no idea how to ask the question more precisely. If someone has a good idea of where to look, I'd appreciate it.
TLDR localhost/blogname/ = fine localhost/blogname/page/2 = fine localhost/blogname/page/3 = total destruction
Probably not necessary, but here's my full index.php:
<?php get_header(); ?>
<!--replace index.php with the list, home.php for the 'main' blog? -->
<?php
$hero_args = array(
"posts_per_page" => "1",
/* 'meta_key' => 'meta-checkbox',
'meta_value' => 'yes' */
);
$hero_args['paged'] = get_query_var( 'paged' )
? get_query_var( 'paged' )
: 1;
$post_args = array(
"posts_per_page" => "3",
"offset" => "1",
);
$pag_args1 = array(
'format' => '?page1=%#%',
'current' => $page1,
'total' => $query1->max_num_pages,
'add_args' => array( 'page2' => $page2 )
);
$heroPost = new WP_Query($hero_args);
// the loop
?>
<?php
/*
if ( $heroPost->have_posts() ) {
while ( $heroPost->have_posts() ) {
$heroPost->the_post();
if ( (int) $heroPost->current_post === 0 ) {
// loop content for hero post
}
}
}*/
?>
<div class = "blog_content_wrap">
<div class = "hero_blog">
<?php $temp_query = $wp_query;
$wp_query = NULL;
$wp_query = $heroPost;?>
<?php if ($heroPost -> have_posts()): ?>
Query contains something
<?php while ($heroPost -> have_posts()):
$heroPost -> the_post();
the_title();?>
<?php endwhile;
?>
<?php else:?>
No posts found, sucker
<?php endif;
wp_reset_postdata();
print_r ($hero_args['paged']);
previous_posts_link( 'Older Posts' );
next_posts_link( 'Newer Posts', $heroPost->max_num_pages );
the_posts_pagination();
$wp_query = NULL;
$wp_query = $temp_query;
?>
</div>
<div class = "blog_grid">
</div>
<div class = "blog_div">
<h1 class = "read_more_title">Blog Navigation</h1>
<form>
<input type="text"></input>
<button>Search</button>
<button>By Category</button>
<button>By Date</button>
<button>List</button>
</div>
</div>
</div>
<?php get_footer(); ?>
<!--<div class = "blog_div">
<h3>tit</h3>
<h4>Olivia Bennett</h4>
<p> ex</p>
<a href="#">Read more</a>
</div>
<div class = "blog_div">
<h3>My Day at the Spinster's House</h3>
<h4>Olivia Bennett</h4>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Doloremque ad quae saepe dolorum.
Sequi quidem doloremque, explicabo, necessitatibus eum dicta perferendis
totam ex dolor at eos quae aliquid iusto fugiat?</p>
<a href="#">Read more</a>
</div>
<div class = "blog_div">
<h3>My Day at the Spinster's House</h3>
<h4>Olivia Bennett</h4>
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Doloremque ad quae saepe dolorum.
Sequi quidem doloremque, explicabo, necessitatibus eum dicta perferendis
totam ex dolor at eos quae aliquid iusto fugiat?</p>
<a href="#">Read more</a>
</div>-->