Keyword

[SOLVED] Publishing date in item and category listings

More
9 years 18 hours ago - 9 years 18 hours ago #143252 by Eero
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: 9 years 18 hours ago by Eero. Reason: Forgot to mention K2 and J! version

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 17 hours ago #143255 by Krikor Boghossian
Replied by Krikor Boghossian on 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.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
9 years 17 hours ago - 9 years 17 hours ago #143260 by Eero
Thank you very much Krikor! That solved it! :)

Eero
Last edit: 9 years 17 hours ago by Eero.

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
9 years 17 hours ago #143261 by Krikor Boghossian
Replied by Krikor Boghossian on topic Publishing date in item and category listings
You 're welcome Eero :)

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
5 years 6 months ago - 5 years 6 months ago #169537 by Odin Mayland
Replied by Odin Mayland on 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: 5 years 6 months ago by Odin Mayland.

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

More
5 years 6 months ago - 5 years 6 months ago #169541 by JoomlaWorks
Replied by JoomlaWorks on 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.

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Last edit: 5 years 6 months ago by JoomlaWorks.

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

More
5 years 6 months ago #169563 by Odin Mayland
Replied by Odin Mayland on 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.

More
5 years 6 months ago #169565 by JoomlaWorks
Replied by JoomlaWorks on 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'));
}
?>

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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

More
5 years 6 months ago - 5 years 6 months ago #169569 by Odin Mayland
Replied by Odin Mayland on 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: 5 years 6 months ago by Odin Mayland.

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

More
5 years 6 months ago #169570 by JoomlaWorks
Replied by JoomlaWorks on 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'));
}
?>

Fotis / JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

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


Powered by Kunena Forum