Keyword

Icon when when an article has been updated

  • Aniron79
  • Aniron79's Avatar Topic Author
  • Offline
  • New Member
More
5 years 11 months ago #172353 by Aniron79
Hi, is there a way to make an icon appear in the title when an article has been updated?

Thanks

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

More
5 years 11 months ago #172371 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
Use this:
<?php $updated = ($this->item->modified) ? true : false; ?>

Then check for $updated and attach an extra CSS class or message next to the item title.

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

  • Aniron79
  • Aniron79's Avatar Topic Author
  • Offline
  • New Member
More
5 years 11 months ago #172383 by Aniron79
Replied by Aniron79 on topic Icon when when an article has been updated
in which file should I enter the code?

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

More
5 years 11 months ago #172384 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
You first need to create a set of template overrides inside your Joomla template, for K2, so you won't lose your changes in the future (when you upgrade K2).

See here: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

You'll then need to edit item.php and category_item.php for component views and mod_k2_content's default.php for module views.

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

  • Aniron79
  • Aniron79's Avatar Topic Author
  • Offline
  • New Member
More
5 years 11 months ago #172385 by Aniron79
Replied by Aniron79 on topic Icon when when an article has been updated
Thank you so much!

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

More
5 years 11 months ago #172389 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
You're welcome.

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

More
5 years 9 months ago #172630 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
In regard to this code below, am I placing it in and around the <!-- Start K2 Item Layout --> area on the subtemplate item file?

Also, where can I write the words 'Updated News' in the code as well??

Any help will be great!

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

More
5 years 9 months ago #172635 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
This is part of the actual item output, so you either edit the category_item.php file (in the K2 sub-templates) for the item output in category listings or item.php for the direct item output.

If you choose item.php for example, you place the code wherever you like. Something like:
<?php $updated = ($this->item->modified) ? true : false; ?>
<?php if ($updated): ?>
<b>The article was recently updated!</b>
<?php endif; ?>

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

More
5 years 9 months ago - 5 years 9 months ago #172648 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
Ok great that works ok with just the words in my item.php...

I just need to figure out how to have it appear for only recently modified items (within the past 2 weeks or so)

As per my other post, I read through the post about 'Publishing date in item and category listings' you mentioned and believe I need something like this below?

<?php echo JHTML::_('date', $this->item->modified, JText::_('K2_DATE_FORMAT_LC2')); ?>
Last edit: 5 years 9 months ago by Chris Hogan.

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

More
5 years 9 months ago #172664 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
You need to convert the modified date to a unix timestamp (using e.g. strtotime($this->item->modified)) and do the same with the current time (strtotime("now")). Subtract the modified unix timestamp from the current time (also in unix timestamp) and if the difference is smaller than 2 days (divide the difference with the number of seconds contained in 2 days - 60* 60 * 24 * 2) then show a different message.

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

More
5 years 9 months ago #172693 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
Thanks but can we please do this one step at a time as I have literally no idea what you posted.

Step 1: "You need to convert the modified date to a unix timestamp" (using e.g. strtotime($this->item->modified)) where do I need to do this?

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

More
5 years 9 months ago #172700 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
Here's the code you need for everything:
<?php
// First check if the item was modified/updated at all
$isUpdated = ($this->item->modified) ? true : false;

if ($isUpdated) {
    // The item is recently updated, so get it's modified date and convert to a unix timestamp
    $dateModified = strtotime($this->item->modified);

    // Get the current time as a unix timestamp
    $now = time();

    // Calculate the difference in days
    $diff = ($now - $dateModified)/(3600 * 24);

    // Check if the difference is less than 2 days & output some message
    if ($diff < 2) {
        echo '<span>Item was recently updated!</span>';
    }
}
?>

Use that in your own item.php template override.

Learn how to copy K2 source template overrides into your Joomla template by reading this: getk2.org/documentation/tutorials/174-templating-with-k2-and-the-concepts-of-sub-templates

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

More
5 years 9 months ago #172724 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
Hi, many thanks for putting that together, I'm just having some issues getting it to appear on site.

This code will ideally go on my category item.php but I've tried to add the above to both item & category php files in nearly every position on each page to no aval, plus I also used the standard K2 files with just this code added...again it didn't seem to appear anywhere??

Is there something I still need to add to this or is there an option I need to apply in Joomla/K2 backend even though its hard coded?

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

More
5 years 9 months ago - 5 years 9 months ago #172732 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
Let's start with the basics... Did the items you check actually have a modified date?
Last edit: 5 years 9 months ago by JoomlaWorks.

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

More
5 years 9 months ago #172738 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
Nope! I mustn't have been on an item that had been updated in the past 2 days - which I believe it was setup to show!

But its all ok now & it is showing great, I just completely rushed the testing in my haste to see the code working...

I've actually added it to the 'Featured flag' area (see attached) on my category pages and removed the <?php echo JText::_('K2_FEATURED'); ?> as words 'Featured' were literally displaying on every item & didn't it really stand out at all on my Category pages anyway.

But I'm really happy with this though, and I'm sure it will be useful to others (as not all items added to sites can be brand new stories every time) so giving the user a clue if you've modified on an old item is a really good feature!

Just one final thing though on the Homepage; which file am I to upload for this to display there...is it just the category.php??
Attachments:

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

More
5 years 9 months ago #172741 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
It's category_item.php to be exact.

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

More
5 years 9 months ago - 5 years 9 months ago #172749 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
Ok that's strange as I have the code working in the category_item.php in the position below, but it doesn't appear to want to show on the homepage??


<code>
<?php if($this->item->params->get('catItemFeaturedNotice') && $this->item->featured): ?>
<!-- Featured flag -->
<span>
<sup>

<?php
// First check if the item was modified/updated at all
$isUpdated = ($this->item->modified) ? true : false;

if ($isUpdated) {
// The item is recently updated, so get it's modified date and convert to a unix timestamp
$dateModified = strtotime($this->item->modified);

// Get the current time as a unix timestamp
$now = time();

// Calculate the difference in days
$diff = ($now - $dateModified)/(3600 * 24);

// Check if the difference is less than 2 days & output some message
if ($diff < 14) {
echo '<span>Recently Updated!</span>';
}
}
?>

</sup>
</span>
<?php endif; ?>
</h3>
<?php endif; ?>

</code>
Last edit: 5 years 9 months ago by Chris Hogan.

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

More
5 years 9 months ago #172750 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
Ok that's strange as I have the code working in the category_item.php in the position below, but it doesn't appear to want to show on the homepage??

 	<?php if($this->item->params->get('catItemFeaturedNotice') && $this->item->featured): ?>
	  	<!-- Featured flag -->
	  	<span>
		  	<sup>
		  		
		  	<?php
// First check if the item was modified/updated at all
$isUpdated = ($this->item->modified) ? true : false;

if ($isUpdated) {
    // The item is recently updated, so get it's modified date and convert to a unix timestamp
    $dateModified = strtotime($this->item->modified);

    // Get the current time as a unix timestamp
    $now = time();

    // Calculate the difference in days
    $diff = ($now - $dateModified)/(3600 * 24);

    // Check if the difference is less than 2 days & output some message
    if ($diff < 14) {
        echo '<span>Recently Updated!</span>';
    }
}
?>
		  		
	  	</sup>
	  	</span>
	  	<?php endif; ?>
	  </h3>
	  <?php endif; ?>

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

More
5 years 9 months ago #172762 by JoomlaWorks
Replied by JoomlaWorks on topic Icon when when an article has been updated
Your homepage may retrieve K2 content from a module or some other view. That's why you don't see it.

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

More
5 years 8 months ago #172982 by Chris Hogan
Replied by Chris Hogan on topic Icon when when an article has been updated
I was about to email about the Homepage and my News sections not working with the code above...but the problem was that I had a test sub-template that I did a while back 'Select a template' option set up in the menus under "Layout options for multiple category selection"

ALL IS WORKING OK NOW! BRILLANT FEATURE THIS LOVE IT!

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


Powered by Kunena Forum