Output yearly archive within a page

You can just use a normal query to grab all posts (which are, by default, sorted date descending), and break them up as you loop over them: <?php $posts = new WP_Query( array( ‘posts_per_page’ => -1, ‘post_type’ => ‘press-releases’ ) ); if ( $posts->have_posts() ) : ?> <ul class=”accordion”><?php while ( $posts->have_posts() ) : $posts->the_post(); … Read more

Including post_type = ‘wiki’ in author archives

Author archives default to searching for posts of the post type post. You could override this with wiki like so; function wpse_11210_set_wiki_for_author( $query ) { if ( $query->is_main_query() && $query->is_author() ) $query->set( ‘post_type’, ‘wiki’ ); } add_action( ‘pre_get_posts’, ‘wpse_11210_set_wiki_for_author’ ); Drop it in your a plugin or your theme’s functions.php (if the file doesn’t exist, … Read more

Sort custom-posts in archive.php via meta-key?

Just use the appropriate conditionals: function change_order_for_events( $query ) { //only show future events and events in the last 24hours $yesterday = current_time(‘timestamp’) – 24*60*60; if ( $query->is_main_query() && (is_tax(‘event_type’) || is_post_type_archive(‘wr_event’)) ) { $query->set( ‘meta_key’, ‘_wr_event_date’ ); $query->set( ‘orderby’, ‘meta_value_num’ ); $query->set( ‘order’, ‘ASC’ ); //Get events after 24 hours ago $query->set( ‘meta_value’, $yesterday … Read more

How do I make wp_get_archives show me months where only pages were created?

The wp_get_archives() function runs a filter on its WHERE clause–it’s called getarchives_where. You could use this to modify the query to only include pages rather than posts (which is the hard-coded default). I haven’t tested this yet, but try it out: add_filter(‘getarchives_where’,’my_archives_filter’); function my_archives_filter($where_clause) { return “WHERE post_type=”page” AND post_status=”publish””; } Then, just use the … Read more

How do I visit archive-post.php?

You don’t, archive-post.php doesn’t exist, it’s just archive.php, and on most sites the post archive is the root of the site, aka /. Depending on how you’re viewing posts it’ll use home.php, front-page.php, index.php, etc. You should refer to the template hierarchy diagram, but remember, the standard post post type is a special case, as … Read more

Archive widget – limit number of months to 12

Use the widget_archives_args filter to add the archives limit. function my_limit_archives( $args ) { $args[‘limit’] = 12; return $args; } add_filter( ‘widget_archives_args’, ‘my_limit_archives’ ); And to limit the number of months in Archives widget dropdown use the following drop down filter. add_filter( ‘widget_archives_dropdown_args’, ‘my_limit_archives’ );

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

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

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