New answers tagged

0

What happens next? Nothing. That's it. Loading the template is the last thing that happens. I suppose the post loop in the template gets executed. When the template is loaded the PHP code in it just gets run like any other PHP code. Most templates should include a pattern of code that's called 'the loop'. This code does what the documentation says it does....


0

ob_get_flush doesn't do what you think it does. You're assuming that it only ends the output buffer and returns its contents, which is incorrect, it also flushes the output buffer to the browser. So this: return ob_get_flush(); Is the same as this: $content = ob_get_clean(); echo $content; return $content; Use ob_get_clean(); instead, which erases the ...


1

The solutions here are all good but were not consistent with both local and remote server environments. So I came up with a simpler neat solution that works better regardless of the WordPress permalink settings. function getCurrentUrl() { $protocol = is_ssl() ? 'https://' : 'http://'; return ($protocol) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'...


0

Is it okay to call global $post; inside the loop in ajax or is there a better way to access the current post object? I'd do it outside the loop but in the same scope to avoid duplication, but otherwise the answer is: If it works, then it works, don't stress about it, there is no canonical one way to rule them all for this. global $post; works, and there is ...


1

delete the following line of code if ( ( $posts->current_post + 1 ) === $posts->post_count ) echo '</li>'; leaving only the following portion <?php $last_year = $year; endwhile; ?>


0

SOLVED with the magic of paginate_links (after the endwhile) <?php $big = 999999999; // need an unlikely integer echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '?paged=%#%', 'current' => max( 1, get_query_var('paged') ), 'total' => $loop->max_num_pages ) );...


Top 50 recent answers are included