Add inline HTML to posts published within last 24hrs
Compare the current time with the UNIX time stamp of the post date: // now minus one day in seconds if ( ( time() – 86400 ) < get_the_date( ‘U’ ) ) { echo ‘<span class=”new”>New!</span>’; }
Compare the current time with the UNIX time stamp of the post date: // now minus one day in seconds if ( ( time() – 86400 ) < get_the_date( ‘U’ ) ) { echo ‘<span class=”new”>New!</span>’; }
You can use a custom Walker, the easiest of which in your case is the Walker_Category and extend it like so: class CategoryThumbnail_Walker extends Walker_Category { // A new element has been stumbled upon and has ended function end_el( &$output, $category, $depth, $args ) { // Output the standard link ending parent::end_el( &$output, $category, $depth, … Read more
Just define a variable, and concat all html as string and return it. <?php function services_shortcode( $atts ) { // Attributes extract( shortcode_atts( array( ‘slug’ => ”, ), $atts ) ); $html=””; if ( isset( $slug ) ) { $args = array( ‘post_type’ => ‘cbd_services’, ‘name’ => $slug ); // -1 Shows ALL Posts $loop … Read more
Standard Loop: <?php while ( have_posts() ) : the_post(); ?> <?php get_template_part( ‘content’, get_post_format() ); ?> <?php endwhile; ?> Loop checking for 4th post: <?php $i = 0; while ( have_posts() ) : the_post(); $i++; ?> <?php if(!$i%4): get_template_part( ‘content’, get_post_format() . ‘-4th’ ); ?> <?php else: get_template_part( ‘content’, get_post_format() ); endif; ?> <?php endwhile; … Read more
When you specify a meta_key, query_posts() does an INNER JOIN between the wp_posts and wp_postmeta table. That means that any posts that don’t have any meta value for the key you specified won’t ever be returned in that query. In order to do what you need, you should use the same query you posted in … Read more
One solution would be- $terms = get_terms(‘taxonomy-name’); foreach($terms as $term) { $posts = get_posts(array( ‘post_type’ => ‘custom_post_type_name’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘taxonomy-name’, ‘field’ => ‘slug’, ‘terms’ => $term->slug ) ), ‘numberposts’ => -1 )); foreach($posts as $post) { // do what you want to do with the posts here } }
REWORKED APPROACH Due to this becoming a bit of tameletjie due to styling issues, lets rework everything and look at a different approach I think what we should do here is to rather shuffle the $posts array through usort() to get the posts sorted in the order we want, and then there after we can … Read more
This took a bit of trial and error but I think I got it. I was getting an infinite loop until I added suppress_filters. After that it was short work. function insert_post_wpse_96347($posts) { global $wp_query; $desired_post = 151; if (is_main_query() && is_home() && 0 == get_query_var(‘paged’)) { $p2insert = new WP_Query(array(‘p’=>$desired_post,’suppress_filters’=>true)); $insert_at = 3; if … Read more
Strictly, you don’t need to use a loop in a page template, but it doesn’t hurt, the content of the page will still load, the loop will simply only run once as there is only one post/page. Many themes include a loop in page templates, I guess for some compability issue. If you are building … Read more
Check out your php.ini config file and try changing the permissions for your upload_tmp_dir & session.save_path directories.