Link for the page archive for posts, like using custom post types with get_post_type_archive_link

I use a shortcode: function shortcode_article_list() { $posts_array = get_posts( array(‘posts_per_page’ => -1, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’) ); $output=”<ul>”; foreach ($posts_array as $post) { $a = explode(‘ ‘, $post->post_date); $output .= ‘<li><a href=”‘ . home_url(“https://wordpress.stackexchange.com/”) . $post->post_name . ‘.html”>’ . $post->post_title . ‘</a> (‘ . $a[0] . … Read more

How can I change the way dates shown in the archive widget?

For archives you can use the get_archives_link filter like this: add_filter(‘get_archives_link’, ‘translate_archive_month’); function translate_archive_month($list) { $patterns = array( ‘/January/’, ‘/February/’, ‘/March/’, ‘/April/’, ‘/May/’, ‘/June/’, ‘/July/’, ‘/August/’, ‘/September/’, ‘/October/’, ‘/November/’, ‘/December/’ ); $replacements = array( //PUT HERE WHATEVER YOU NEED ’01.’, ’02.’, ’03.’, ’04.’, ’05.’, ’06.’, ’07.’, ’08.’, ’09.’, ’10.’, ’11.’, ’12.’ ); $list = preg_replace($patterns, … Read more

Count posts for each year

The Easy Way This is by far and away the easiest approach to this, but unless you are willing to be a little bit flexible with how you present your archive it’s not for you. The easy solution is achieved using the wp_get_archives() function. Unfortunately though there is no filter available to manipulate the output, … Read more

How to have Multiple Archives Widgets, one archive widget per category (in a different page)?

I finally found an answer using WordPress rewrites. The whole code is at the end and can be pasted in functions.php. There is just one parameter that you have to change $rules = cpt_generate_date_archives(‘news’, $wp_rewrite); news is the name of the post_type. So I added a second line to show how to have two archives. … Read more

Custom post type with tags

Yes, both assignments do the same, but the post_tag archive is using the post type post only by default. Don’t worry, there is a hook for you: pre_get_posts. Example with tags for pages: // register tags for pages add_action( ‘wp_loaded’, ‘wpse_75297_register_tags_for_pages’ ); function wpse_75297_register_tags_for_pages() { register_taxonomy_for_object_type( ‘post_tag’, ‘page’ ); } // add post type ‘page’ … Read more

Change permalink for default archive – yearly

It should work but note that the date structure contains the structure for year, month and day archives as well, so you’ll need something like: add_action( ‘init’, function() { global $wp_rewrite; $wp_rewrite->date_structure=”archives/%year%/%monthnum%/%day%”; }); Don’t forget to visit your permalinks settings page in wp-admin so that rewrite rules are flushed.

Making next_posts_link(); return posts by month

You have to modify the query that selects the posts to select by month. This bit of code placed in the template will get the page number and subtract that from the current month. <?php $page = get_query_var(‘paged’) ? get_query_var(‘paged’) : 1; $subtractor = $page-1; $date = date(“Y-m-d H:i:s”); $current_month = date(‘n’, strtotime($date.’-‘.$subtractor.’months’)); $current_year = … Read more

How to make a custom Archive Page

You can get the queried date from the query vars in the $wp_query object: if( is_date() ){ if( isset( $wp_query->query_vars[‘year’] ) ){ echo ‘queried year is ‘ . $wp_query->query_vars[‘year’]; } if( isset( $wp_query->query_vars[‘monthnum’] ) ){ echo ‘queried month is ‘ . $wp_query->query_vars[‘monthnum’]; } if( isset( $wp_query->query_vars[‘day’] ) ){ echo ‘queried day is ‘ . $wp_query->query_vars[‘day’]; … Read more

How to get the date dynamically from archive.php to date.php?

It’s working very fine after I made some changes / adding on two php files function.php and date.php function.php function wpa_date_posts_per_page( $query ) { if ( !is_admin() && $query->is_date() && $query->is_main_query() ) { $query->set( ‘posts_per_page’, -1 ); } } add_action( ‘pre_get_posts’, ‘wpa_date_posts_per_page’ ); date.php <?php get_header(); while (have_posts()) : the_post(); echo the_title() . ‘<br/><br/>’; endwhile; … Read more

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