Displaying posts on Homepage

Try the following using WP_Query: <div class=”news-column”> <h3>Latest News</h3> <ul> <?php //get news $args->posts_per_page = 5; //query $query = new WP_Query($args); while($query->have_posts()):$query->the_post(); ?> <li class=”news-item”> <h4><?php the_title(); ?></h4> <p><?php the_date(‘F jS, Y’); ?></p> <?php the_excerpt(); ?> <p class=”footnotes”><a href=”https://wordpress.stackexchange.com/questions/69725/<?php the_permalink(); ?>”>Continue reading</a></p> </li> <?php endwhile; wp_reset_postdata(); ?> </ul> </div> You can read more about other … Read more

Show last post from multiple categories using wp_list_categories

Get all children categories using get_terms(). Loop through each term and run a new query using tax_query. Example: <?php if ( get_queried_object()->parent == 0 ) : // parent cat ?> <h2>Showing all children</h2> <?php $args = array( ‘hide_empty’ => false, ‘parent’ => get_queried_object()->term_id ); $terms = get_terms( ‘category’, $args ); if ( $terms ) echo … Read more

get_post_custom_values not working

It most probably means that no custom post values have been retrieved for the key Description that you used. According to the Codex, Returns nothing if no such key exists, or none is entered. Try adding print_r($key_values); on the line just after get_post_custom_values(“Description”); and check if any value is retrieved. To skip this warning(when you … Read more

Query specific number of posts for each post type in specific order

You can use WP_Query() with paged array key to pass the current page number: <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $args = array( ‘post_type’ => ‘articles’, ‘posts_per_page’ => 4, ‘paged’ => $paged ); $articles = new WP_Query($args); //////////////////////////////// $args = array( ‘post_type’ => ‘news’, ‘posts_per_page’ => 1, ‘meta_query’ => array( array( ‘key’ => … Read more

Show posts in a list separated by day

Add a variable to hold the previous post’s date, and then add a <br /> or something when it changes. <?php $prev_date=””; // initialize to empty string query_posts($query_string.’&cat=-3′); while (have_posts()) : the_post(); ?> <?php if( strlen( $prev_date ) > 0 && get_the_time( ‘M j’ ) != $prev_date ): ?> <br /> <!– or whatever you … Read more

shortcode for recent custom type post

This seems to work with custom post type : function get_custom_posts( $params ) { extract( shortcode_atts( array ( ‘number’ => ‘1’, ‘excerpt’ => 290, ‘readmore’ => ‘no’, ‘cpt’ => ‘post’, ‘readmoretext’ => ‘Read more’ ), $params ) ); //$latest_posts = get_posts( ‘category=0&numberposts=” . $number . “&suppress_filters=false’); OLD $latest_posts = query_posts( ‘post_type=”.$cpt.”&posts_per_page=” . $number ); wp_reset_query(); … Read more

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