Thomas Venugopal
Hello,
Example url: /testpage/?cid=
0344
I have this php script:
- It reads the cid value from the URL, which in this case is
0344.
- It searches the Joomla database for an article in category 301 that has a custom field with ID 41 whose value is
0344.
Since there is one article with the ID 1512 that meets these conditions, 1512 would be the result of the query.
{source}
<?php
// get 'cid'-parameter from url
$cid = JFactory::getApplication()->input->getString('cid');
// check it parameter is present
if ($cid) {
// Verbindung zur Datenbank herstellen
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// search article in categorie 301, where the custom field 'c-cid' has the value of the url parameter 'cid'
$query->select($db->quoteName('a.id'))
->from($db->quoteName('#__content', 'a'))
->join('INNER', $db->quoteName('#__fields_values', 'fv') . ' ON ' . $db->quoteName('a.id') . ' = ' . $db->quoteName('fv.item_id'))
->where($db->quoteName('a.catid') . ' = 301')
->where($db->quoteName('fv.field_id') . ' = 41') // Custom Field ID
->where($db->quoteName('fv.value') . ' = ' . $db->quote($cid));
$db->setQuery($query);
$result = $db->loadResult();
// echo article id
if ($result) {
echo $result;
} else {
echo 'no article';
}
} else {
echo 'no cid';
}
?>
{/source}
The result with the url /testpage/?cid=
0344 is 1512.
Now I'd like to change the following tag so that the result of the query is in the id field of the following tag.
{article id="1512"}{article-hl id="[c-hl:value]"}[text]{/article-hl}{/article}
I tried to put the php script with sourcerer into the id tag like this but that doesn't work:
{article id="{source}
<?php
// get 'cid'-parameter from url
$cid = JFactory::getApplication()->input->getString('cid');
// check it parameter is present
if ($cid) {
// Verbindung zur Datenbank herstellen
$db = JFactory::getDbo();
$query = $db->getQuery(true);
// search article in categorie 301, where the custom field 'c-cid' has the value of the url parameter 'cid'
$query->select($db->quoteName('a.id'))
->from($db->quoteName('#__content', 'a'))
->join('INNER', $db->quoteName('#__fields_values', 'fv') . ' ON ' . $db->quoteName('a.id') . ' = ' . $db->quoteName('fv.item_id'))
->where($db->quoteName('a.catid') . ' = 301')
->where($db->quoteName('fv.field_id') . ' = 41') // Custom Field ID
->where($db->quoteName('fv.value') . ' = ' . $db->quote($cid));
$db->setQuery($query);
$result = $db->loadResult();
// echo article id
if ($result) {
echo $result;
} else {
echo 'no article';
}
} else {
echo 'no cid';
}
?>
{/source}"}{article-hl id="[c-hl:value]"}[text]{/article-hl}{/article}
Is it possible to combine these two plugins?