using the loop on a page

To use template tags within a foreach loop outputting the results of get_posts, use the function setup_postdata() to populate the global $post with the data it needs. To style the first post differently, use a counter to keep track of which post you’re outputting. After finishing output, use wp_reset_postdata() to restore the $post global. wp_reset_query … Read more

2 loops in blog homepage

You can use this code to get 3 posts from category Featured $args = array( ‘category_name’ => ‘featured’, ‘posts_per_page’ => 3 ); $featured_posts = new WP_Query( $args ); if ( $featured_posts->have_posts() ): while ( $featured_posts->have_posts() ): $featured_posts->the_post(); // Here you can use the normal loop functions like ‘the_title()’ to display your // 3 posts from … Read more

show posts from one category with comments only

To retrieve all posts from a category, while preserving the original Loop query, you create a new query like so: <?php $testimonials = new WP_Query( array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘post’, ‘posts_per_page’ => 30, // limit number of posts for which to get ALL the comments of ‘category__in’ => array( 2, 6, 18 ) … Read more

Changing the loop w/o killing category links

Okay, assuming you only want to restrict the categories for the front page, but still list all categories everywhere else, just add the according template file to your theme: front-page.php <?php get_header(); ?> <?php $my_query = new WP_Query(‘cat=79,120’); ?> <?php if ($my_query->have_posts()) : ?> <div id=”post-area”> <?php while ($my_query->have_posts()) : $my_query->the_post(); ?> <div id=”post-<?php the_ID(); … Read more

display only parent replies count in index.php

Based on this answer I suggest the following code: // the theme’s functions.php /** * Get the number of top level comments for a post. * * @param int $post_id * @return int */ function wpse_95242_top_level_comments_for_post( $post_id = NULL ) { if ( NULL === $post_id ) $post_id = get_the_ID(); if ( ! $post_id ) … Read more

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