3

I'm looking for php code in article page to check if the article is published or not.

I tried this one, but it false.

if($listing['Listing']['published']==1){ }

Could anyone give me some hint? Thanks a lot

PS: Joomla 1.7.3, JReviews 2.3(using Joomla default content structure)

Anson Wong
  • 33
  • 4
  • If you're viewing articles through article/default.php then you should only be able to see published articles, could you give us more information WHERE this code is going? It makes a big difference. – udjamaflip Jan 08 '12 at 22:22
  • The query that selects the articles for display either in the component area or any of the modules only selects modules that are published by default. There is no need to test that because any article selected would necessarily be published. – Brent Friar Jan 09 '12 at 07:17

1 Answers1

2

Try this:

jimport('joomla.database.table');
$article_id = [place here the article Id];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo $article->get("state");

you can find more info here

Nir Alfasi
  • 53,191
  • 11
  • 86
  • 129
  • 1
    Does this check whether the article is between `publish_up` and `publish_down` dates? – Flimm Apr 20 '16 at 15:50
  • @Flimm the question was if the article was published or not. The contract is: state: 0 for unpublished, 1 for published, -1 for archived. The date of publication is not related to the state. – Nir Alfasi Apr 20 '16 at 16:48
  • 1
    I'm not talking about the date of publication, I'm talking about the "Start Publishing" date and the "Finish Publishing" date. If today's date is outside of that range, the article should be considered unpublished, regardless of the `state` column, I think. See https://docs.joomla.org/Scheduling_an_Article_to_be_available_only_between_certain_dates – Flimm Apr 21 '16 at 08:55
  • @Flimm interesting question, I'm not sure how these two features play together. If it was designed properly, the `state` should be 0 when: Current Date < Start Date or Current Date > End Date – Nir Alfasi Apr 21 '16 at 15:32