Archive by Year

The Simple Yearly Archive Plugin does just that. This code will also do the trick: <?php // get years that have posts $years = $wpdb->get_results( “SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type=”post” AND post_status=”publish” GROUP BY year DESC” ); foreach ( $years as $year ) { // get posts for each year $posts_this_year = … Read more

What is archive.php used for?

index.php and archive.php might be the same but don’t have to be the same. index.php will display your blog post archive and in the absence of archive.php (or other more specific archive files) it will display your date, author, etc. archives as well. But it doesn’t have to. You can, if you want, display your … Read more

$wp_query initiation?

User Rarst has a very famous answer where he lays out the load process. Looking at this graph whenever wp-blog-header.php gets loaded it calls function wp() which sets up many of WordPress globals like $post and $wp_query. ( Secondary Reference by User Gmazzap ) That’s the technical side of things but it looks like the … Read more

is_archive() returns false on the archives page

Because an “archives” Page is not an archive index of blog Posts, but rather a Page. An “archives” page is simply a custom Page template, which applies to a static Page. The is_archive() conditional returns true if an archive index is being displayed. An archive index page displays Posts, not static Pages. EDIT Instead of … Read more

Preventing 404 error on empty date archive

You can move the code from OP’s answer into a 404 template filter and force WP to load the date.php file instead of 404.php. It’ll still send the 404 header, but render the page with a different template. function wpd_date_404_template( $template=”” ){ global $wp_query; if( isset($wp_query->query[‘year’]) || isset($wp_query->query[‘monthnum’]) || isset($wp_query->query[‘day’]) ){ $template = locate_template( ‘date.php’, … Read more

How can I get the Month Name from Archive?

If you want to get the month of the current archive page you’ll have to use single_month_title. The following code will output ” August 2014″ (notice the space before the month) <?php single_month_title(‘ ‘) ?> Without a space before the month: <?php echo trim(single_month_title(‘ ‘,false)) ?> Read more: http://codex.wordpress.org/Function_Reference/single_month_title

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