WordPress Alphabetical Glossary close div in loop

If you search the site, most of the “display nth post different” questions are very closely related to this one, and honestly this is more a PHP + logic question that a WordPress one. if (have_posts()) { $curr_letter=””; echo ‘<div class=”alphawrapper”>’; while (have_posts()) { the_post(); $title = get_the_title(); $title_array = explode(‘ ‘, $title); $second_word = … Read more

Identify the page being shown while in The Loop

I believe you want get_queried_object. That will return information about the page per se and not necessarily about the posts/pages being displayed in the Loop. Be aware that it returns very different information depending on the type of page you are one. It will return user information on an author archive, for example, but category … Read more

Two custom loops, pagination, offset

I can’t use only one Loop because of how complicated my markup is. Markup, no matter how complicated, should never ever be a valid basis when coming to deciding to run multiple loops. Multiple loops should only ever be used if there is absolutely no other means to achieve a certain result, and that is … Read more

Multiple posts with one loop iteration

Ultimately, this question is off-topic, because the solution has nothing to do with WordPress. Outputting posts in a grid pattern is an HTML/CSS issue, and the best-practice solutions don’t involve putting every three posts inside a separate containing <div>. Even so, you can do what you want to do, using PHP (which, technically speaking, still … Read more

Count singular post views automatically

You could hook into template_redirect and execute a helper function: add_action( ‘template_redirect’, ‘wpse_75558_count’ ); function wpse_75558_count() { if ( is_singular() ) setPostViews( get_the_ID() ); } To display the post views, you have to use a later hook. I would recommend the_content: add_filter( ‘the_content’, ‘wpse_75558_show_count’ ); function wpse_75558_show_count( $content ) { $count = getPostViews( get_the_ID() ); … Read more