Keyword

Display on k2-items that are at least one year old?

  • Odin Mayland
  • Odin Mayland's Avatar Topic Author
  • Offline
  • Platinum Member
More
6 days 4 hours ago - 6 days 4 hours ago #169102 by Odin Mayland
Odin Mayland created the topic: Display on k2-items that are at least one year old?
Advanced Module Manager allows for a module assignment using custom php. The docs state:

Enter a piece of PHP code to evaluate. The code must return the value true or false.


I was planning to display a Custom-HTML module in the Below-Content position to display some tex on all k2-items in a specified category that are at least one year old?

It appears that this is the code that displays the date in a k2-item:

<?php if($this->item->params->get('itemDateCreated')): ?>
<!-- Date created -->
<span class="itemDateCreated">
<?php echo JHTML::_('date', $this->item->created , JText::_('K2_DATE_FORMAT_LC2')); ?>
</span>
<?php endif; ?>

I assume the custom PHP is going to be like this example:
return ( $user->name == 'Peter van Westen' );

Can you help me write the custom PHP to return a true for a k2-item that is at least one year old?
Last Edit: 6 days 4 hours 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
5 days 23 hours ago #169108 by Fotis
Fotis replied the topic: Display on k2-items that are at least one year old?
It's better to do a K2 item override for this as no module can have access to the K2 item data object unless it retrieves it with an SQL query or uses the K2 item model.

If you do an override, you can have what you want like this:
<?php
if ($this->item->category->id = CATEGORY_ID_HERE) {
    $createdDate = strtotime($this->item->created);
    $oneYearBack = strtotime('now -1 year');
    if ($createdDate > $oneYearBack) { // Item is at least a year old
        // do something
    }
}


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.

  • Odin Mayland
  • Odin Mayland's Avatar Topic Author
  • Offline
  • Platinum Member
More
5 days 9 hours ago - 5 days 9 hours ago #169120 by Odin Mayland
Odin Mayland replied the topic: Display on k2-items that are at least one year old?
Thank you! I got it to work be switching the > to <
<?php
if ($this->item->category->id = 48) {
    $createdDate = strtotime($this->item->created);
    $oneYearBack = strtotime('now -1 year');
    if ($createdDate < $oneYearBack) { echo JHtml::_('content.prepare', '{loadposition disclaimer}'); 

    }
}
?>
Last Edit: 5 days 9 hours 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
5 days 1 hour ago #169123 by Fotis
Fotis replied the topic: Display on k2-items that are at least one year old?
Ah, sorry, kinda read it like "less than a year old" (stupid me).


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