{"id":4145,"date":"2014-01-26T23:32:50","date_gmt":"2014-01-27T07:32:50","guid":{"rendered":"http:\/\/g-liu.com\/blog\/?p=4145"},"modified":"2014-01-26T23:34:17","modified_gmt":"2014-01-27T07:34:17","slug":"how-to-add-a-mini-calendar-next-to-your-wordpress-post","status":"publish","type":"post","link":"https:\/\/g-liu.com\/blog\/2014\/01\/how-to-add-a-mini-calendar-next-to-your-wordpress-post\/","title":{"rendered":"How to add a mini-calendar next to your WordPress post"},"content":{"rendered":"<p>When I installed the <a href=\"http:\/\/wordpress.org\/themes\/iconic-one\" target=\"_blank\">Iconic One<\/a> theme to this blog, I knew at once that it would need some important customizations. One of the most important that I added, was a little calendar beside each post title. Many great WordPress themes have a calendar to display the date of a post. Why not give the same touch to Iconic One?<\/p>\n<p>This tutorial will assume basic familiarity with HTML and CSS. Programming skills, especially PHP, are a plus.<\/p>\n<figure id=\"attachment_4158\" aria-describedby=\"caption-attachment-4158\" style=\"width: 460px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/calendar-post.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4158\" data-permalink=\"https:\/\/g-liu.com\/blog\/2014\/01\/how-to-add-a-mini-calendar-next-to-your-wordpress-post\/calendar-post\/\" data-orig-file=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/calendar-post.png\" data-orig-size=\"460,121\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"calendar-post\" data-image-description=\"\" data-image-caption=\"&lt;p&gt;Example of a post title with calendar. Appears on the post archive pages.&lt;\/p&gt;\n\" data-medium-file=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/calendar-post-300x78.png\" data-large-file=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/calendar-post.png\" class=\"size-full wp-image-4158 \" alt=\"Example of a post title with calendar. Appears on the post archive pages.\" src=\"http:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/calendar-post.png\" width=\"460\" height=\"121\" srcset=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/calendar-post.png 460w, https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/calendar-post-300x78.png 300w\" sizes=\"(max-width: 460px) 100vw, 460px\" \/><\/a><figcaption id=\"caption-attachment-4158\" class=\"wp-caption-text\">Example of a post title with calendar. Appears on the post archive pages.<\/figcaption><\/figure>\n<p><!--more--><\/p>\n<h1>Getting started: Theme inspection<\/h1>\n<p>First, we have to understand how WordPress puts a page together. When you go to a URL on your blog, WordPress is putting together several PHP files and delivering them to you in one big file. To give you a picture of the parts, TutsPlus has put together a nice visualization:<\/p>\n<p><a href=\"http:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy.jpg\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"4159\" data-permalink=\"https:\/\/g-liu.com\/blog\/2014\/01\/how-to-add-a-mini-calendar-next-to-your-wordpress-post\/wp_cheatsheet_themeanatomy\/\" data-orig-file=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy.jpg\" data-orig-size=\"850,1100\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"WP_CheatSheet_ThemeAnatomy\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy-231x300.jpg\" data-large-file=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy-791x1024.jpg\" class=\"alignnone  wp-image-4159\" alt=\"WP_CheatSheet_ThemeAnatomy\" src=\"http:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy.jpg\" width=\"850\" height=\"1100\" srcset=\"https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy.jpg 850w, https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy-231x300.jpg 231w, https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy-791x1024.jpg 791w, https:\/\/g-liu.com\/blog\/wp-content\/uploads\/2014\/01\/WP_CheatSheet_ThemeAnatomy-660x854.jpg 660w\" sizes=\"(max-width: 850px) 100vw, 850px\" \/><\/a><\/p>\n<p>From this, we can be sure that we&#8217;re editing the right theme files. Our calendar will probably appear in files like <code>search.php<\/code> or <code>archive.php<\/code>, and not in the <code>footer.php<\/code>.<\/p>\n<h1>Finding the files<\/h1>\n<p>You&#8217;ll need an FTP client for this step, if you already have one. I recommend <a href=\"http:\/\/filezilla-project.org\" target=\"_blank\">FileZilla <\/a>for Windows\/Linux, and <a href=\"http:\/\/cyberduck.io\" target=\"_blank\">Cyberduck <\/a>for Mac.<\/p>\n<ol>\n<li>Navigate to your <code>public_html<\/code> folder. Your webhost should have the details on where this is<\/li>\n<li>Now, go to your blog directory, which should be on the same folder as in the URL. For example, if your blog was at <code>example.com\/blog<\/code>, there should be\u00a0a <code>blog\/<\/code> folder in public_html.<br \/>\nIf you see three folders <code>wp-content<\/code>, <code>wp-admin<\/code>, and <code>wp-includes<\/code>, then you should be in the right place.<br \/>\nIf you&#8217;re not sure where your WordPress blog folder is, contact your webhost.<\/li>\n<li>Navigate to: <code>wp-content\/themes\/[your-theme]<\/code>. <code>[Your-theme]<\/code> should be similar to the name of your theme. This is where all the theme files are stored.<\/li>\n<li>Now for the most challenging part: Finding out where exactly to put the calendar. Since each theme is a bit different, the exact file in which you put the calendar code can vary. Try looking first in <code>single.php<\/code>, which represents a single blog post. Then\u00a0try looking for the line of code: <code>&lt;?php the_title(); ?&gt;<\/code>, as this displays the post title.<br \/>\nIf you don&#8217;t see it, then chances are that the post title could be in a different theme file.<\/li>\n<\/ol>\n<h1>Putting in the code<\/h1>\n<p>The code in itself is pretty compact. Figuring out where exactly to put it is the hard part. I like to put my code right before the <code>div<\/code> where <code>&lt;?php the_title(); ?&gt;<\/code> appears. I&#8217;ve commented the code below so that you can see exactly what&#8217;s going on.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n&lt;?php \r\n\t$df = 'd M Y'; \/\/ e.g '09 Dec 2013'. Date format\r\n\t$date = get_the_date($df); \/\/ gets the date of the post\r\n\tlist($day, $month, $year) = explode(' ',$date); \/\/ sets day, month, and year of the post\r\n?&gt;\r\n&lt;div class=&quot;entry-date&quot;&gt;&lt;!-- begins the calendar --&gt;\r\n\t&lt;span class=&quot;month&quot;&gt;&lt;?php echo $month; ?&gt;&lt;\/span&gt;\r\n\t&lt;span class=&quot;day&quot;&gt;&lt;?php echo $day; ?&gt;&lt;\/span&gt;\r\n\t&lt;?php if($year != date('Y')) : \/\/ shows year if post year is not the current year ?&gt;\r\n\t&lt;span class=&quot;year&quot;&gt;&lt;?php echo $year; ?&gt;&lt;\/span&gt;\r\n\t&lt;?php endif; ?&gt;\r\n&lt;\/div&gt;\r\n&lt;!-- This concludes the mini calendar --&gt;\r\n<\/pre>\n<p>We&#8217;re not quite done yet. This code by itself won&#8217;t by any means look pretty. In order to make it look like a calendar we&#8217;re going to need some CSS.<\/p>\n<p>Copy and paste the following CSS into your theme&#8217;s stylesheet, usually <code>style.css<\/code><\/p>\n<pre class=\"brush: css; title: ; notranslate\" title=\"\">\r\ndiv.entry-date {\r\n\tfloat: left;\r\n\twidth: 64px;\r\n\tborder: 1px solid #16A1E7;\r\n\tbackground-color: #ededed;\r\n\tmargin: -1px 19px -1px -1px;\r\n}\r\ndiv.entry-date .month {\r\n\tbackground-color: #16A1E7;\r\n\tdisplay: block;\r\n\ttext-align: center;\r\n\tfont-weight: bold;\r\n\tpadding: 2px;\r\n\tcolor: white;\r\n}\r\ndiv.entry-date .day {\r\n\tfont-size: 36px;\r\n\ttext-align: center;\r\n\tbackground-color: #ededed;\r\n\tdisplay: block;\r\n\tpadding: 3px 0px;\r\n\tcolor: rgb(68, 68, 68);\r\n}\r\ndiv.entry-date .year {\r\n\ttext-align: center;\r\n\tfont-size: 11px;\r\n\tdisplay: block;\r\n\tpadding: 2px 0px;\r\n\tmargin-top: -2px;\r\n\tborder-top: 1px dotted rgba(22, 163, 233, 0.50);\r\n\tbackground-color: #e6e6e6;\r\n}\r\n<\/pre>\n<p>You are encouraged to tweak this to your liking, but be careful not to change any of the <code>display:<\/code> properties. These are what keeps the HTML in line and looking like a calendar.<\/p>\n<h1>Testing the theme<\/h1>\n<p>Upload your changes via FTP, and hit Refresh. You should now have a beautiful, simple calendar right next to your posts.<\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content --><!-- AddThis Related Posts generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>When I installed the Iconic One theme to this blog, I knew at once that it would need some important customizations. One of the most important that I added, was a little calendar beside each post title. Many great WordPress themes have a calendar to display the date of a post. Why not give the same touch to Iconic One? &#8230;<!-- AddThis Advanced Settings generic via filter on wp_trim_excerpt --><!-- AddThis Share Buttons generic via filter on wp_trim_excerpt --><!-- AddThis Related Posts generic via filter on wp_trim_excerpt --><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"How to add a mini-calendar next to your #WordPress post http:\/\/wp.me\/p2Zt3y-14R","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[830,58],"tags":[],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2Zt3y-14R","_links":{"self":[{"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/posts\/4145"}],"collection":[{"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/comments?post=4145"}],"version-history":[{"count":6,"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/posts\/4145\/revisions"}],"predecessor-version":[{"id":4165,"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/posts\/4145\/revisions\/4165"}],"wp:attachment":[{"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/media?parent=4145"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/categories?post=4145"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/g-liu.com\/blog\/wp-json\/wp\/v2\/tags?post=4145"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}