{"id":77423,"date":"2012-05-04T10:00:30","date_gmt":"2012-05-04T14:00:30","guid":{"rendered":"http:\/\/wpmu.org\/?p=77423"},"modified":"2012-05-04T11:03:04","modified_gmt":"2012-05-04T15:03:04","slug":"how-to-group-wordpress-posts-by-date-on-your-homepage","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/how-to-group-wordpress-posts-by-date-on-your-homepage\/","title":{"rendered":"How to Group WordPress Posts by Date on Your Homepage"},"content":{"rendered":"<p><a rel=\"lightbox[77423]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-group-wordpress-posts-by-date-on-your-homepage\/planner-big\/\" rel=\"attachment wp-att-77425\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-77425 aligncenter\" title=\"planner-big\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/planner-big.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"651\" height=\"429\" \/><\/a><br \/>\nIf you\u2019ve ever wanted a way for your visitors to quickly scan down a list of your posts on your homepage, then the following little trick will allow you to group your posts together by date so they will look something along the lines of the following:<\/p>\n<p><a rel=\"lightbox[77423]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-group-wordpress-posts-by-date-on-your-homepage\/group-by-date\/\" rel=\"attachment wp-att-77426\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77426\" title=\"group-by-date\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/group-by-date.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"639\" height=\"609\" \/><\/a><\/p>\n\n<h2><\/h2>\n<h2><strong>The Code<\/strong><\/h2>\n<p>You will need to edit the code on your homepage for this to work, and so you may want to <a href=\"http:\/\/codex.wordpress.org\/Child_Themes\" rel=\"noopener\" target=\"_blank\">make a child theme<\/a> first so that you won\u2019t need to touch your original theme. Barring that, it would be a good idea to make sure you have a copy of your homepage (index.php) safely stored away.<\/p>\n<p><strong>Step 1:<\/strong> To edit you homepage, go to Archives &gt; Editor &gt; Main Index Template \u2013 index.php.<\/p>\n<p><strong>Step 2:<\/strong> Find the spot in your code where the \u201ccontent\u201d begins. This will often be identified with a div that looks something along the lines of the following (yours may differ a little):<\/p>\n<pre>&lt;div id=\"content\" role=\"main\"&gt;<\/pre>\n<p><strong>Step 3:<\/strong> After finding the opening div, go toward the bottom of the page and find the closing div for the content. This div will look something along the lines of the following (again, your theme may differ \u2013 there may be no notations for the closing div):<\/p>\n<pre>\u00a0&lt;\/div&gt;&lt;!-- end #content --&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Step 4:<\/strong> Delete everything between the opening content div and the closing content div.<\/p>\n<p><strong><span style=\"color: #ff0000;\">Note:<\/span> This is a radical step that will completely wipe out your posts on your front page (temporarily). For this reason you should make sure you have a copy of your original index.php file in case something goes wrong.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Step 5:<\/strong> Place the following code in between the opening content div and the closing content div.<\/p>\n<pre>&lt;?php\r\n$day_check = '';\r\nwhile (have_posts()) : the_post();\r\n\u00a0 $day = get_the_date('j');\r\n\u00a0 if ($day != $day_check) {\r\n\u00a0\u00a0\u00a0 if ($day_check != '') {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0 echo '&lt;\/ul&gt;'; \/\/ close the list here\r\n\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0 echo get_the_date() . '&lt;ul&gt;';\r\n\u00a0 }\r\n?&gt;\r\n&lt;li&gt;&lt;a href=\"&lt;?php the_permalink() ?&gt;\"&gt;&lt;?php the_time(); ?&gt; &lt;b&gt;&lt;?php the_title(); ?&gt;&lt;\/b&gt;&lt;\/a&gt;&lt;\/li&gt;\r\n&lt;?php\r\n$day_check = $day;\r\nendwhile; ?&gt;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 &lt;?php if ( have_posts() ) : ?&gt;\r\n&lt;?php endif; ?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<h2><strong>The Style of Your Grouped Posts<\/strong><\/h2>\n<p>The style of your list will be determined by your theme\u2019s styles. However, you should get something that looks somewhat like the following:<\/p>\n<p><a rel=\"lightbox[77423]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-group-wordpress-posts-by-date-on-your-homepage\/homepage-2\/\" rel=\"attachment wp-att-77427\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77427\" title=\"homepage\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/homepage.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"639\" height=\"682\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>This will be a very basic look, of course, and so you may try styling it with CSS if you\u2019re comfortable doing that.<\/p>\n\n<p>&nbsp;<\/p>\n<h2><strong>Some Basic Tips<\/strong><\/h2>\n<p><strong>Tip 1:<\/strong> If you don\u2019t want the time of the posts to appear, then can remove the following piece of code from code given above:<\/p>\n<pre>&lt;?php the_time(); ?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Tip 2:<\/strong> You can unbold the title by deleting the<strong> &lt;b&gt;<\/strong> and the <strong>&lt;\/b&gt;<\/strong> from the following snippet of code:<\/p>\n<pre>&lt;b&gt;&lt;?php the_title(); ?&gt;&lt;\/b&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Tip 3:<\/strong> Because this will greatly reduce the amount of space it takes to list a post on your homepage, you may want to increase the number of posts shown there. Do this by going to <strong>Settings &gt; Reading<\/strong>:<\/p>\n<p><a rel=\"lightbox[77423]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/how-to-group-wordpress-posts-by-date-on-your-homepage\/reading-settings\/\" rel=\"attachment wp-att-77428\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-77428\" title=\"reading-settings\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/05\/reading-settings.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"638\" height=\"544\" \/><\/a><\/p>\n<p>(Code adapted slightly from <a href=\"http:\/\/wordpress.stackexchange.com\/questions\/34598\/group-posts-by-date-with-a-list\" rel=\"noopener\" target=\"_blank\">stackexchange<\/a>.)<\/p>\n\n<p>&nbsp;<\/p>\n<p>Photo: <a href=\"http:\/\/www.bigstockphoto.com\/image-4171857\/stock-photo-daily-planner\" target=\"_blank\">Daily Planner<\/a> from BigStock<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Make it easy for your visitors to skim down a list of your posts on your front page.<\/p>\n","protected":false},"author":84404,"featured_media":77424,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[263],"tags":[],"tutorials_categories":[],"class_list":["post-77423","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/77423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=77423"}],"version-history":[{"count":1,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/77423\/revisions"}],"predecessor-version":[{"id":216213,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/77423\/revisions\/216213"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/77424"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=77423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=77423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=77423"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=77423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}