- Posts: 5
COMMUNITY FORUM
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Publishing date in item and category listings
[SOLVED] Publishing date in item and category listings
- Eero
-
Topic Author
- Offline
- New Member
From the K2 categories I can select "Item created date and time" and "Item modified date and time", and if set to "show", these will be visible in the category and item views. All good.
But what if I want to display the date when the item is published? For example, if I have a blog or news list in the main k2 container, and there are blog posts showing the dates when they were created, but I want to list the publishing dates instead?
Is there an alternative script I could use in the custom K2 template to replace the "JHTML::_('date', $this->item->created" string? I tried "item->published" but it resulted the date showing 1.1.1970.
This is irritating, especially as I want to write many articles in advance and then set them to be automatically published on later dates. I am also using Latest News Enhanced module to show news feed / latest blog posts on the side of the page, and it shows K2 published dates well.
Eero
Ps. K2 version 2.6.8 and Joomla 3.3.6
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Also publish_up should be used instead of published. Published is a boolean and it will not return a date.
Please Log in or Create an account to join the conversation.
- Eero
-
Topic Author
- Offline
- New Member
- Posts: 5
Eero
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Please Log in or Create an account to join the conversation.
- Odin Mayland
-
- Offline
- Platinum Member
- Posts: 404
I too want to display the published date. Can you help me edit this so it works?
<?php echo JText::_(Published on); ?> <?php echo JHTML::_('date', $this->item->publish_up, JText::_('K2_DATE_FORMAT_LC2')); ?>
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
<?php echo JHTML::_('date', $this->item->created, JText::_('K2_DATE_FORMAT_LC2')); ?>
with this:
<?php echo JHTML::_('date', $this->item->publish_up, JText::_('K2_DATE_FORMAT_LC2')); ?>
The available dates you have in the item object are: "created", "modified", "publish_up" & "publish_down".
Keep in mind that in modules it'll probably be $item->publish_up instead of $this->item->publish_up.
Please Log in or Create an account to join the conversation.
- Odin Mayland
-
- Offline
- Platinum Member
- Posts: 404
Now is there any way to not display the modified date if its the same as the published date?
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
<?php
if ($this->item->modified != $this->item->publish_up) {
echo JHTML::_('date', $this->item->modified, JText::_('K2_DATE_FORMAT_LC2'));
}
?>
Please Log in or Create an account to join the conversation.
- Odin Mayland
-
- Offline
- Platinum Member
- Posts: 404
Last thing.... :-) .... The modified date is still showing so maybe I need to know how you get the date to not use the time to be used in the if comparison?
www.icd10monitor.com/the-value-of-a-certified-coder-and-cdi-in-our-practices
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
<?php
$datePublished = JHTML::_('date', $this->item->publish_up, '%Y%m%d');
$dateModified = JHTML::_('date', $this->item->modified, '%Y%m%d');
if ($dateModified != $datePublished) {
echo JHTML::_('date', $this->item->modified, JText::_('K2_DATE_FORMAT_LC2'));
}
?>
Please Log in or Create an account to join the conversation.
- Odin Mayland
-
- Offline
- Platinum Member
- Posts: 404
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
I'd really appreciate it if you could take a moment to add your review (and rating) for K2 at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/
Please Log in or Create an account to join the conversation.
- Odin Mayland
-
- Offline
- Platinum Member
- Posts: 404
Please Log in or Create an account to join the conversation.
- JoomlaWorks
-
- Offline
- Admin
- Posts: 6227
Please Log in or Create an account to join the conversation.
- Forum
- K2 Community Forum
- English K2 Community
- [SOLVED] Publishing date in item and category listings