You can use the Transients API to cache the entire HTML output so the queries are not done every time the page is loaded:
$transient="my-300-posts";
$timeout = 3600; // 1 hour
if ( false === $out = get_transient( $transient ) ) {
$args = array( YOUR ARGS GO HERE );
$posts = get_posts( $args );
if ( $posts ) {
foreach ( $posts as $post ) {
$out .= get_the_title( $post->ID );
$out .= // whatever else you want to output...
}
}
if ( $out ) {
set_transient( $transient, $out, $timeout );
}
}
echo $out;
However, you’re still serving 300 post thumbnails on one page load, which is a lot of data to transfer.
(You also need to delete the transient on the save_post
and delete_post
hooks)
Maybe you’d be better off with infinite scrolling? It’s an option in the Jetpack plugin.