2

I want to show the published date inside a module, how can I do that? I will make of course a module override and use the changes inside the default.php

Thank you

  • this comment came after my answer below - can you clarify what exactly you want to do - it's not clear. – FFrewin Mar 22 '17 at 12:29
3

The following should work for what it sounds like you are trying to achieve. If you are on an article page, it displays the published date of that article or else shows nothing.

// FIRSTLY CHECK THAT THE PAGE THE MODULE APPEARS ON IS AN ARTICLE
$nameofcomponent = JRequest::getVar('option');
$viewofcomponent = JRequest::getVar('view');

if ($nameofcomponent=="com_content" && $viewofcomponent=="article" ) {

    // IT IS AN ARTICLE, SO GET THE ID OF THE ARTICLE
    $idofarticle = JRequest::getInt('id');

    // LOAD THE MODEL OF COM_CONTENT
    $model = JModelLegacy::getInstance('Article', 'ContentModel');
    // USE THE GETITEM FUNCTION OF THE MODEL TO RETURN THE DETAILS
    $article = $model->getItem($idofarticle);


      // FORMAT AND PRINT THE DATE TO THE SCREEN
      $date = new JDate($article->created);
      echo $date->format('j M Y');

}

If this is what you are trying to do, however, then it sounds like there may be a design issue - I can't imagine a usibility reason why you'd want to show this information in a module rather than the component area.

  • Thank you, it worked. I want it to show the date of the article on the top module with a banner on the same page. A quick fix for the date format? I want to be like: 12 Mar 2017. – geoplous Mar 22 '17 at 13:07
  • Added a format example - read up on JDate in Joomla and PHP:date if you want to fiddle with that. – Richard B Mar 22 '17 at 13:15
0

The module has to support this - meaning that it has first to fetch and have available these data in its content items object/array through whatever method it uses to call the articles.

Usually if it supports that, then it should have the relative options in its backend.

If it doesn't support this, then either look for another module - there are plenty articles display modules available in JED - or develop your own.

Note: maybe I have mis-understood your question though.

0

You can use the Module from: https://db8.eu/ to display article creating, updated Date to any module position

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.