2016-06-28 13 views
0

Wie schreibe ich ein Modul, das an Artikel Tagen von der Veröffentlichung angezeigt wird?Joomla Datum von der Veröffentlichung

Ich schrieb so etwas, aber es scheint nicht jedes Mal zu funktionieren.

Könnt ihr mich korrigieren?

{source} 

<?php 
    $option = JRequest::getCmd('option'); 
    $view = JRequest::getCmd('view'); 
    if ($option=="com_content" && $view=="article") { 
    $ids = explode(':',JRequest::getString('id')); 
    $article_id = $ids[0]; 
    $article =& JTable::getInstance("content"); 
    $article->load($article_id); 
    $date = new JDate($article->get("publish_up")); 

    $currentTime = new JDate('now'); 

    $interval = $date->diff($currentTime); 

    if($interval->d == 0) { 
      echo 'dzisiaj' . "<br>"; 
     } 
     else if($interval->d == 1) { 
      echo 'wczoraj' . "<br>"; 
     } 
     else if($interval->d > 1) { 
      echo $interval->format('%a dni temu') . "<br>"; 
     } 


} 

?> 

{/source} 

Antwort

0

Die Art, wie Sie die Artikel-ID erhalten, sieht seltsam aus. Versuchen Sie stattdessen etwas wie folgt aus:

$app = JFactory::getApplication(); 
$article_id = $app->input->getInt('id'); 

Diese verwendet die aktuelle joomla api zum Abrufen von HTTP-Variablen (more info here)

Noch nicht, daß ich genau sehen, warum Ihr Code sollte die Art und Weise fehlschlagen Sie es tun ...

+0

Ich habe es getan, und jetzt funktioniert es, aber es wird falsch ID des Artikels. Es sollte 41 bekommen, wird aber 22. $ article_id = JFactory :: getApplication() -> Eingabe -> get ('id'); Ich denke, dass diese Zeile nicht funktioniert, wie es funktionieren sollte; –

0

Danke, aber jetzt habe ich so etwas wie dieses

{source} 
<?php 


    $app = JFactory::getApplication(); 
    $article_id = $app->input->getInt('id'); 
    $article =& JTable::getInstance("content"); 
    $article->load($article_id); 
    $date = new JDate($article->get("published")); 
    $currentTime = new JDate('now'); 
    echo $date; 
    $interval = $date->diff($currentTime); 

    if($interval->d == 0) { 
      echo 'dzisiaj'; 
     } 
     else if($interval->d == 1) { 
      echo 'wczoraj'; 
     } 
     else if($interval->d > 1) { 
      echo $interval->format('%a dni temu'); 
     } 




?> 

{/source} 

und es funktioniert jetzt, aber es zeigt incorect Datum publish.

Verwandte Themen