Query the Loop without breaking it

That’s a really inefficient way to do it. Just use the $count variable you declared at the top, without any query_posts(): $count = 0; while ( have_posts() ) : the_post(); if ( $count < 1 ) { // first post } elseif ( $count <= 4 ) { // next 4 posts } else { … Read more

wp remove query

I’m assuming you’re talking about this piece of maintenance code right here: http://core.trac.wordpress.org/browser/tags/3.3.1/wp-admin/includes/post.php#L419 Indeed, the code calls on lower level functionality of $wpdb, which doesn’t contain too many hooks, only one in fact, query. http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/wp-db.php#L1061 So, in order to return an empty result set you’ll have to come up with a no-operation type of query, … Read more

Insert html after certain amount of posts?

You could use the following and it should do exactly what you want by checking the value of $loop->current_post. <?php $loop = new WP_Query( array( ‘post_type’ => ‘work’,’posts_per_page’ => ‘-1’ ) ); ?> <ul id=”carousel”> <li> <ul class=”inner-items”> <?php while ( $loop->have_posts() ) : $loop->the_post(); ?> <?php if( $loop->current_post && !($loop->current_post % 6) ) : … Read more

How to get category link without a database query

It’s down to how you’re using get_term_link() – since you’re passing a slug, WordPress can’t locate the term in it’s internal cache (terms are indexed by ID), so it grabs it directly from the db. To use the cache, pass the ID. Better yet, pass just the object: get_term_link( $category ); // No need for … Read more

Different Main Navigation per category

You could set this in your theme using conditionals. Create a separate menu for each category using the WordPress menu feature (Appearances > Menus). Then in your theme, where you want the menu to display, determine which menu to display using the is_category(‘category-slug’) and/or in_category(‘category-slug’) conditionals and the wp_nav_menu function (http://codex.wordpress.org/Function_Reference/wp_nav_menu). For instance: <?php if(is_category(‘first-category’) … Read more

When add_query_arg() is necessary?

The difference is, in “plugin_part1-fixed.php” you wouldn’t lose existing args. Consider the url: https://www.example.com/page/?foo=bar Your code in “plugin_part1.php” would output <a href=”https://www.example.com/page/?custom_var=column”>text</a> Note, the existing arg “foo” has been lost, the code in “plugin_part1-fixed.php” would output: <a href=”https://www.example.com/page/?foo=bar&custom_var=column”>text</a> Note, the existing arg “foo” is still present and your arg has been appended. Since you don’t … Read more

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