Keyword

[SOLVED] Publishing date in item and category listings

More
3 years 7 months ago - 3 years 7 months ago #143252 by Eero
Eero created the topic: Publishing date in item and category listings
Hello,

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
Last Edit: 3 years 7 months ago by Eero. Reason: Forgot to mention K2 and J! version

Please Log in or Create an account to join the conversation.

More
3 years 7 months ago #143255 by Krikor Boghossian
Krikor Boghossian replied the topic: Publishing date in item and category listings
You should update to 2.6.9

Also publish_up should be used instead of published. Published is a boolean and it will not return a date.

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

Please Log in or Create an account to join the conversation.

More
3 years 7 months ago - 3 years 7 months ago #143260 by Eero
Eero replied the topic: Publishing date in item and category listings
Thank you very much Krikor! That solved it! :)

Eero
Last Edit: 3 years 7 months ago by Eero.

Please Log in or Create an account to join the conversation.

More
3 years 7 months ago #143261 by Krikor Boghossian
Krikor Boghossian replied the topic: Publishing date in item and category listings
You 're welcome Eero :)

IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

---
JoomlaWorks
www.joomlaworks.net/

Please Log in or Create an account to join the conversation.

More
2 months 4 days ago - 2 months 4 days ago #169537 by Odin Mayland
Odin Mayland replied the topic: Publishing date in item and category listings
Krikor,

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')); ?>
		
Last Edit: 2 months 4 days ago by Odin Mayland.

Please Log in or Create an account to join the conversation.

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 months 4 days ago - 2 months 4 days ago #169541 by Fotis
Fotis replied the topic: Publishing date in item and category listings
In the item view (and override item.php) swap this:
<?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.


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member
Last Edit: 2 months 4 days ago by Fotis.

Please Log in or Create an account to join the conversation.

More
2 months 4 days ago #169563 by Odin Mayland
Odin Mayland replied the topic: Publishing date in item and category listings
That worked great!

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.

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 months 3 days ago #169565 by Fotis
Fotis replied the topic: Publishing date in item and category listings
<?php 
if ($this->item->modified != $this->item->publish_up) {
    echo JHTML::_('date', $this->item->modified, JText::_('K2_DATE_FORMAT_LC2'));
}
?>


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

Please Log in or Create an account to join the conversation.

More
2 months 3 days ago - 2 months 3 days ago #169569 by Odin Mayland
Odin Mayland replied the topic: Publishing date in item and category listings
Wow, you're amazing!

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
Attachments:
Last Edit: 2 months 3 days ago by Odin Mayland.

Please Log in or Create an account to join the conversation.

  • Fotis
  • Fotis's Avatar
  • Offline
  • Administrator
  • JoomlaWorks Support Team
More
2 months 3 days ago #169570 by Fotis
Fotis replied the topic: Publishing date in item and category listings
Format the dates down to day-level and compare:
<?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'));
}
?>


If you use & love K2, please take a moment to add your review and rate it
at the Joomla Extensions Directory: extensions.joomla.org/extension/k2/


IMPORTANT: Please search the forum before posting a question!

JoomlaWorks Support Team Member

Please Log in or Create an account to join the conversation.

Moderators: william white