Page template not displaying

This is less of an answer and more of a kind of troubleshooting aid… Add this function to your project (probably functions.php) and then call it from the top of every template file in your theme… /** * Outputs the name of the file as an HTML comment for easy-peesy troubleshooting. * * @param string … Read more

How can I use get_permalink() outside the loop?

Since you are calling get_permalink() outside of the loop, you need to define the post $id parameter. You can access the post ID outside of the loop by invoking the global $post object and then referencing it’s ID value. So your code would now look like this: <?php if ( ICL_LANGUAGE_CODE==’zh-hans’ ) : global $post; … Read more

How to sort posts in archive loop

This filter has to be set in functions.php. Your filter won’t work as expected because your condition is wrong. The condition here imply that you try to order pages (hierarchical post) instead of regular posts-like entries. You have to be careful using this filter as it has effect on your whole website. function my_custom_archive_order( $vars … Read more

Exclude first 2 posts with meta_key from loop

First point is that you should NOT use query_posts() for custom queries. The better approach is to use the WP_Query class. More info in the WP docs and here. This example will display your 2 featured posts and then exclude them in the second query. // We will push the ID of your featured posts … Read more

WordPress Loop – Style rows of posts differently

It’s basically only some math, but you can use $wp_query properties perfectly for that case: Increment global $wp_query; if ( have_posts() ) { while ( have_posts() ) { the_post(); printf( ‘<div %s>%s</div>’, get_post_class( “style-{$wp_query->current_post}” ), // OR: // get_post_class( “style-“.++$wp_query->wpse66475_increment_posts ) ); } } // endif; So the 1st time, your style-n would increment by … Read more

The Loop in Static Page

This quite a broad question to answer. I’m not going to go into detail here and into core code, you’ll need to go and read the links I’m going to provide. I’m going to try to keep my answer sweet and short and useful 🙂 Take the bundled theme twentyfourteen for example, when you open … Read more

Run The Loop over array of post objects

I’m using this in one of my custom widgets: global $post; $posts = array( /* WP_Post, WP_Post, … */); while (list($i, $post) = each($posts)) : setup_postdata($post); // use the template tags below here if(has_post_thumbnail()): ?><div class=”featured_image_wrap”><?php the_post_thumbnail(); ?></div><?php endif; the_title(); endwhile; // don’t forget to restore the main queried object after the loop! wp_reset_postdata();

Users instead of posts: How to modify the main query?

Custom GET pagination parameter We can use a custom GET pagination parameter, e.g. upage or probably more unique as wpse-user-page, to use with your WP_User_Query. That way you avoid affecting e.g. the main post query. Generate pagination links with pageinate_links() We can use paginate_links() to generate the pagination: $args = array( ‘base’ => ‘%_%’, ‘format’ … Read more

Check if date of post is yesterday

As you discovered, one possible solution is something like: <?php $w_h = $w_d = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php if ( date(‘Yz’) == get_the_time(‘Yz’) ) { if (!$w_d++) echo ‘Today<br />’; } elseif ( date(‘Yz’)-1 == get_the_time(‘Yz’) ) { if (!$w_h++) echo ‘Yesterday<br />’; } else { echo the_date(); }; ?>

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