Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Show a k2 extrafield for current article
Show a k2 extrafield for current article
Show a k2 extrafield for current article
Hello, thanks in advance for your time. I'm trying to display a k2 extrafield content on a module using metamod. So far i've managed to show metamod just on k2 items using.
Code:
if ($option == "com_k2" and $view == "item")
Now i need to get the, for example, content of the extrafield named "map" for the k2 article i'm reading and show it in the metamod module, I've followed the instructions suggested here http://jbeginner.com/tutorials/extensio … ra-fields/ and added if
Code:
($option == "com_k2" and $view == "item") echo $extrafields[4];
but the result is the same content for every article, even if the extra field content is different. Any idea?
OpEn YoUr MiNd
Re: Show a k2 extrafield for current article
Hi Kuato,
unfortunately the code suggested on that link is only for putting inside K2 layouts, and it assumes that the $this->item object contains the K2 object so you can get the extra fields from it. When you are inside the PHP code of a module on the page, $this does not point to the same thing, so you'll need to get hold of $this->item->extrafields some other way.
One way to get this is to use the JomGenius K2 object, like this:
$k2 = JomGenius("k2");
$fields = $k2->info("item_extra_fields");
if ($fields != "") {
$fields = json_decode($fields);
$extrafields = array();
foreach($fields as $item) {
$extrafields[$item->id] = $item->value;
}
// do something with the data here, e.g.
echo $extrafields[0]; // where the index is the extra fields "id"
}
Hope that helps,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » Show a k2 extrafield for current article
Board Info
- Board Stats:
- Total Topics:
- 1698
- Total Polls:
- 6
- Total Posts:
- 5944
- Posts this week:
- 4
- User Info:
- Total Users:
- 5533
- Newest User:
- gregg25476
- Members Online:
- 0
- Guests Online:
- 132
- 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