Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Return latest 5 article ids...
Return latest 5 article ids (frontpage) as paramater
Return latest 5 article ids (frontpage) as paramater
Hi,
Is it possible to return the last 5 latest articles as article ids as a parameter to feed into a module in the format 5,4,3,2,1. Also can the returned ids only be from articles that are frontpage selected in the joomla backend. Any help appreciated.
Thanks,
Adam
Re: Return latest 5 article ids (frontpage) as paramater
Hi Adam,
it just takes a little PHP code to make a database query to get the 5 latest articles with "frontpage" selected, in reverse order. However, the trick is what you want to happen next. Do you already have a module in mind that can take these parameters and use them to display links to the articles?
It only makes sense for me to write some code if you can provide some more info about how the data is going to be used, and exactly what data you need - e.g. article IDs or titles? And what's the module that's going to use these for display?
Thanks,
Stephen
Re: Return latest 5 article ids (frontpage) as paramater
Hey Stephen,
Yeah the module has an param input for article numbers in the example format, 1,2,3,4,5, where 1,2,3,4,5 are the article id. I would like to return the articles in reverse order 5,4,3,2,1, where the 5-1 are the last 5 article ids published 5 being the last article, and frontpage selected. If you can could you tell me which bit of code could be rewritten to handle frontpage = No selected articles.
Thanks
Adam
Re: Return latest 5 article ids (frontpage) as paramater
Hi Adam,
what's the module? And, do these parameters go into a single text field, or are there separate text fields for each one of the 5?
The last thing I need to know is what the parameter name of that parameter (or 5 parameters) is/are. You can find them by examining the mod_XXXX.xml file inside the module code. You'll see lines like:
<param name="this_is_the_name_here" type="text" default="" label="Article IDs" description="description here..." />
... and it's the "this_is_the_name_here" that we need for the MetaMod code.
Cheers,
Stephen
Re: Return latest 5 article ids (frontpage) as paramater
Ok looked at the backend. There are two modules I would like to try
Module 1. The parameter single field is called article_ids and they need to be in the order of 5, 4, 3, 2, 1. This is for the frontpage = yes module. Notice the spaces between numbers.
Module 1. The parameter single field is called specifics and they need to be in the order of 5, 4, 3, 2, 1. This is for the frontpage = No module. Notice the spaces between numbers.
could you also advise how to increase/decrease the number of articles.
Thanks in advance,
Adam
P.S. Can I contact you offline re compensation for all the extra code writing. you have my email address from the profile.
Re: Return latest 5 article ids (frontpage) as paramater
ok, here's a recipe for getting the 5 most recent frontpage articles, inserting the ids into the "article ids" parameter of a module, then returning that module.
Code:
$module_to_return = XXX; /* replace XXX with the module id of that module */
$limit = 5; /* alter this to change number of articles */
$nullDate = $db->Quote( $db->getNullDate() );
$jnow =& JFactory::getDate();
$now = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
$query = "SELECT id "
. " FROM #__content c, #__content_frontpage fp "
. " WHERE c.state = 1 "
. " AND c.id = fp.content_id "
. " AND ( c.publish_up = $nullDate "
. " OR c.publish_up <= $now )"
. " AND ( c.publish_down = $nullDate "
. " OR c.publish_down >= $now )"
. " ORDER BY c.created desc "
. " LIMIT $limit ";
$db->setQuery( $query );
$ids = $db->loadResultArray();
$ids = array_reverse($ids);
$list = implode(", ", $ids);
$changes->mod( $module_to_return )->setParam( "article_ids", $list );
return $module_to_return;
Recipe for getting 5 most recent articles that are NOT on frontpage, and inserting the ids in the "specifics" parameter of a module:
Code:
$module_to_return = XXX; /* replace XXX with the module id of that module */
$limit = 5; /* alter this to change number of articles */
$nullDate = $db->Quote( $db->getNullDate() );
$jnow =& JFactory::getDate();
$now = $db->Quote( $db->getEscaped( $jnow->toMySQL() ) );
$query = "SELECT id "
. " FROM #__content c LEFT JOIN #__content_frontpage fp on c.id = fp.content_id "
. " WHERE c.state = 1 "
. " AND fp.content_id is null "
. " AND ( c.publish_up = $nullDate "
. " OR c.publish_up <= $now )"
. " AND ( c.publish_down = $nullDate "
. " OR c.publish_down >= $now )"
. " ORDER BY c.created desc "
. " LIMIT $limit ";
$db->setQuery( $query );
$ids = $db->loadResultArray();
$ids = array_reverse($ids);
$list = implode(", ", $ids);
$changes->mod( $module_to_return )->setParam( "specifics", $list );
return $module_to_return;
- Index
- » MetaMod
- » MetaMod General Support
- » Return latest 5 article ids...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 2
- User Info:
- Total Users:
- 7655
- Newest User:
- martha48
- Members Online:
- 0
- Guests Online:
- 136
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked