What is the best way to get the first few post from WordPress in different divs using a loop?

Use this code for the loop. I removed your comments and added some for clarification. <?php if ( have_posts() ) { // Do first post. add_filter( ‘the_content’, ‘narga_excerpts’ ); add_filter( ‘the_content’, ‘remove_first_image’ ); the_post(); get_template_part( ‘content’, get_post_format() ); // Do remaining posts. remove_filter( ‘the_content’, ‘narga_excerpts’ ); remove_filter( ‘the_content’, ‘remove_first_image’ ); while ( have_posts() ) { … Read more

Error trying import one category on page

As per the codex query_posts Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. Double Note: query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the … Read more

Pagination not working with custom loop

I’ve run into this problem with PageNavi before. My solution is to hijack the $wp_query variable temporarily and then reassign it after closing the loop. An exmaple: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args=array( ‘post_type’=>’post’, ‘cat’ => 6, ‘posts_per_page’ => 5, ‘paged’=>$paged ); $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query($args); /* … Read more

Display Custom Taxonomy of custom post type

I am assiming you already register taxonomy which show you correct links (and generate correct rewrite rules)… but lets make a checklist. 1) Register Taxonomy and assign it to different post types done by you… 2) Modify a rewrite rules add_filter(‘locations_rewrite_rules’, ‘se_119400_locations_rewrite_rules’); function se_119400_locations_rewrite_rules(){ $rules = array(); $rules[‘location(/?(([^/]+?)(/page/?([0-9]{1,})/?)?)?)$’] = ‘index.php?locations=$matches[3]&paged=$matches[5]&post_type=any’; return $rules; } 3) Taxonomy … Read more

Make assigning post to a specific category equivalent to assigning it to all categories

One way to deal with the problem is to use the redirect_canonical filter to cancel the redirect (that happens when the category that the post is assigned to doesn’t match the category slug in the requested post URL) for posts assigned to International (intl) category. /* * Related core file: wp-includes/canonical.php * * NOTE: If … Read more

Category slug in in loop always the same?

First, Please don’t use query_posts.. Second, you’ve set $category somewhere in code not posted and never change it. How do you expect it to be different? What you need to do is retrieve the categories, which isn’t that hard… $cq = new WP_Query(‘category__in=4′); while ( $cq->have_posts() ) { $cq->the_post(); $c = wp_get_object_terms($post->ID,’category’); var_dump($c); // echo … Read more

Printing direct descendants of a category with WP_Query

From the Codex: child_of (integer) Display all categories that are descendants (i.e. children & grandchildren) of the category identified by its ID. There is no default for this parameter. If the parameter is used, the hide_empty parameter is set to false. And… parent (integer) Display only categories that are direct descendants (i.e. children only) of … Read more

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