Identify which loop you are hooking into; primary or secondary?

Just a quick update that a new method is_main_query() has been introduced in WP 3.3. Example: add_action( ‘pre_get_posts’, ‘foo_modify_query_exclude_category’ ); function foo_modify_query_exclude_category( $query ) { if ( $query->is_main_query() && ! $query->get( ‘cat’ ) ) $query->set( ‘cat’, ‘-5’ ); } Resources: WPDevel: New API in 3.3: is_main_query() Codex reference: is_main_query() Related Trac Ticket #18677

Reverse chronology of post listing

You can add code below to the beginning of loop.php add_action(‘pre_get_posts’, ‘wpse_change_post_order’); function wpse_change_post_order($query){ $query->set(‘order’,’ASC’); $query->set(‘orderby’,’date’); } the oldest posts will be in the home page.

Grab the first paragraph of each post

You can use this function: function get_first_paragraph(){ global $post; $str = wpautop( get_the_content() ); $str = substr( $str, 0, strpos( $str, ‘</p>’ ) + 4 ); $str = strip_tags($str, ‘<a><strong><em>’); return ‘<p>’ . $str . ‘</p>’; } and then call it in your loop with: <?php echo get_first_paragraph(); ?> The magic part your looking for … Read more

Pagination with 5 posts per page

This is working for me on a single page using a template. Just be sure to set next_posts_link( ‘Older Entries »’, $the_query->max_num_pages );. // set the “paged” parameter (use ‘page’ if the query is on a static front page) $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : ‘1’; $args = array … Read more

Loop through all tags & output posts in alphabetical list

(Untested) but should works with any taxonomy including the ‘tag’ taxonomy (post_tag). The following example uses the taxonomy with name ‘my-taxonomy’. <?php //Get terms for this taxonomy – orders by name ASC by default $terms = get_terms(‘my-taxonomy’); //Loop through each term foreach($terms as $term): //Query posts by term. $args = array( ‘orderby’ => ‘title’, //As … Read more

Adding ‘current_post_item’ class to current post in the loop

You should be able to get the queried object id and use that for comparison inside your custom loop.. Before your existing loop code(what you have posted above), but obviously after the opening PHP tag.. global $wp_query; $current_id = $wp_query->get_queried_object_id(); Then somewhere inside your custom WP loops.. if( $current_id == get_the_ID() ) { // This … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)