This tutorial discusses a method to automatically create an archive page in WordPress showing all your articles chronologically by dates.
Recall that, WordPress by default shows archives by month.
To implement this chronological archival page, we will suggest you to use a separate page template to avoid changing your theme. However, you may directly take the challenge to change the standard archive.php file.
Building the model of a WordPress page
In your theme folder, duplicate the page.php file for reuse the HTML structure of your site. Rename the file for convenience. You might know, we already wrote how to create a PHP file in Windows 7 without any software.
Paste in the first instance these initial lines of code there by telling it is a WordPress template. First add PHP opening.
Then, just after the command php the_content insert this:
previous_year $ = $ year = 0;
$ month = $ previous_month = 0;
$ ul_open = false;
$ my posts get_posts = ('number posts =- 1 & orderby = post_date & order = DESC');
<? php foreach ($ my posts as $ post):?>
<? phpsetup_postdata ($ post);$ Year = mysql2date ('Y', $ post-> post_date); $ month = mysql2date ('n', $ post-> post_date); $ Day = mysql2date ('j', $ post-> post_date); ?> <? php if ($ year! Previous_year = $ | | $ month! = $ Previous_month)?> <? Php if ($ ul_open == true)?> </ul> <? Php endif;?> <h3> <? php the_time ('F Y');> </ h3> <ul> <? php $ ul_open = true;?> <? Php endif;?> <? Php $ year = $ previous_year; previous_month $ = $ month;?> <li> <span> <? php the_time ('F j');> - </ span> <span> <a href = "<? php the_permalink () ?>"><? php the_title (); ?> </ a> </ span> </ li> <? Php endforeach;?> </ ul>
Remember to save the file on your server via FTP in the
Publication of the chronological archive page
Then log into your WordPress admin and then apply the page template we just created.
You can; for example, create a page named Archive. In the Page Attributes module, select Archive (or what ever the name you used to save the page template) as model:
Note: You may need to modify the method for themes which uses own or modified platform.
Pulkit Kaushik says
You need to make your posts more reader friendly. I didn’t understand where to find the_content. Try to be more elaborate next time.
You will find
. You will get reference of both in WordPress Codex.
You are using Elefolio Premium Theme from Woo Themes. Woo Themes uses generic loops. Please contact Woo Themes’ support mentioning this post, they will guide you how to add it.
Although useful, you have made a mockery of the copy/paste by forcing your website credits into the copied text. No one in their right mind would type out the code you have provided.
Christian, we understand its a big problem now for the nice innocent users for copying the code parts in guides.
The idea of enforcing url copyright text was to fight the copy-paste bloggers, your comment gave a nice feedback and we will try to exclude the code parts as soon as possible those are getting in to the codes too. Its not only impossible to type out the code as rightly said by you, but also there is a possibility of getting errors if those are not sanitized / chopped out by the new users, specially for php and .htaccess codes.
Again thank you very much for the feedback.
Thanks for this tutorial. When I applied for socialpark, I got rejected just because my blog was not having chronological archive. With your article my blog was approved. Thanks for sharing.
Congrats. Thanks a lot for reporting it back.