Custom dates on a Joomla site - shorthand PHP?

Hello all.

Some time ago I self-taught myself PHP from a couple of books. I’d consider myself an intermediate coder.

Due to time constraints, I recently switched over to Joomla to manage my blog websites. They contain fictional content. The fictional setting uses the same calendar months and days that Earth does, but the year is formatted as “YCXXX” where XXX represents the numerical year. The YC bit is important, as is the three digit year. The blog articles are written in-character so the date that displays on them is a small but important detail to add immersion.

My non-Joomla websites achieved the date I needed via a MySQL query in my PHP code:

$query = "SELECT [...] DATE_FORMAT(date, '%Y') AS year [...]"; [...] $year = ($row['year'] - 1898); [...] YC$year

So, if I post an article to that website in 2014, the code will output the fictional year as YC116 which is the correct result.

I understand about using overrides in Joomla, and I have located at least one file that seems to be the one that I need. The problem is that while the code in the file is written in PHP, it’s written in a way that is foreign to me. It’s…shorthand? (For lack of a better term.)

[php]<?php $useDefList = (($params->get(‘show_author’)) OR ($params->get(‘show_category’)) OR ($params->get(‘show_parent_category’))
OR ($params->get(‘show_create_date’)) OR ($params->get(‘show_modify_date’)) OR ($params->get(‘show_publish_date’))
OR ($params->get(‘show_hits’))); ?>

[…some other code here…]

<?php if ($params->get('show_create_date')) : ?>
  <dd class="create">
  <?php echo JText::sprintf('COM_CONTENT_CREATED_DATE_ON', JHTML::_('date',$this->item->created, JText::_('DATE_FORMAT_LC2'))); ?>
  </dd>
<?php endif; ?> <?php if ($params->get('show_modify_date')) : ?>
  <dd class="modified">
  <?php echo JText::sprintf('COM_CONTENT_LAST_UPDATED', JHTML::_('date',$this->item->modified, JText::_('DATE_FORMAT_LC2'))); ?>
  </dd>
<?php endif; ?> <?php if ($params->get('show_publish_date')) : ?>
  <dd class="published">
  <?php echo JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHTML::_('date',$this->item->publish_up, JText::_('DATE_FORMAT_LC2'))); ?>
  </dd>
<?php endif; ?>[/php]

I have no idea what to do with the relevant bits of this to get it to do the math with the year that I need. I want the “published date” and the “last updated date” to be the ones that have the manipulated year. “Created date” should be left as the actual real life date.

Can someone help me with this or point me to a resource where I learn this…shorthand PHP?

Thanks!

Well, this is actually a Joomla question. Here is a list of tutorials on how to use PHP with Joomla along with HTML and many others.

Hopefully, you will be able to learn what you need there. Good luck with it.

http://docs.joomla.org/Joomla!_Development_for_Beginners

Thanks for your reply.

Unfortunately, those tutorials are all red linked—meaning they don’t have actual content. The only tutorial that has content is “Setting up your workstation for web development” which isn’t relevant.

Basic PHP tutorial From Joomla! Documentation There is currently no text in this page. You can search for this page title in other pages, or search the related logs, but you do not have permission to create this page.

This is no help. :frowning:

I did originally ask my question on a Joomla forum but received zero replies, which is why I came here instead.

So, you’re saying this style of PHP is unique to Joomla? No wonder I don’t understand it. Perhaps now that I know this I can find a tutorial somewhere.

Interesting and it is Joomla’s site… Well, sorry for that. Here are some others.
I checked them out a little…

http://docs.joomla.org/PHP_essentials

http://docs.joomla.org/Creating_a_basic_Joomla!_template

http://www.siteground.com/tutorials/joomla15/joomla_create_template.htm

All of the tutorials that I found were how to create a template. But, it will teach you how they work.
Then, you might be able to understand how to reverse-program it to help you.

I didn’t mean this is locked into your template, but, how it works is that the calls to Joomla, like
this one “JHTML::_(” with some arguments loads HTML into the template based on the args and
on whatever JHTML does in the Joomla system. So, you have to study JHTML:: to understand
what it places in your template and adjust the args according to what you need to change. It is a
bit complicated to learn your template AND Joomla, too. But, study a bit and when you get a question
on a certain step, let us know. PHP is not Joomla, but, any PHP programmer should be able to solve
a Joomla problem as it is basically just call Joomla routines with args. Wow, not sure if that made sense!

Do you have the site up and running so we could see a sample of the error area or a image of it? Hard to understand what you are asking for with what you showed. For example the old site gets the date from a database. And, then the new one is embedded in the template. But, the code line that prints the published date is:
[php]

<?php echo JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHTML::_('date',$this->item->publish_up, JText::_('DATE_FORMAT_LC2'))); ?>

[/php]
My guess is that the publish date prints ‘date’ using the format named “DATE_FORMAT_LC2”. So, if you can find where this is in the Joomla code, you can create a new version and call it like DATE_FORMAT_LC99 or whatever. Then, in the Joomla code, dup the LC2 format and put in your own version. That would be my guess. I can look at it tomorrow further and see where they hide LC2 data format for you. Bed time here now… 1:30 AM and 7 comes early…

Good luck… And, Good night…

Finally got this resolved. I bumped my thread again on the Joomla forum and got the help I needed. For the sake of completeness, here is an example of what I had to do:

Replace:
[php]<?php echo JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHTML::_('date',$this->item->publish_up, JText::_('DATE_FORMAT_LC2'))); ?>[/php]

With:
[php]<?php echo JText::sprintf('COM_CONTENT_PUBLISHED_DATE', JHtml::_('date', $this->item->publish_up, 'F j')) . ','; ?>

<?php echo 'YC' . (JHtml::_('date', $this->item->publish_up, 'Y') - 1898); ?>[/php]

This has put the weird Joomla PHP coding into a context I can start to understand, which in turn has helped me tweak it further for some other areas of the template I needed to customize. Now that I know this is specific to Joomla it definitely will help me discover answers on my own in the future. :slight_smile:

Here is the site with the dates working: http://solitarypilot.incyanity.net/

Thanks for your help!

Well, I didn’t help much, but, very glad to see you figured it out. As with all programming, it is just finding the right start to get the mental processes moving. Good work tracking down the fix. I will mark this one solved!

Sponsor our Newsletter | Privacy Policy | Terms of Service