- Posts: 438
COMMUNITY FORUM
Custom K2 Content Module Assistance
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
I saw that @MohamedAbdelaziz recommended BNR Content for K2 on this forum post:
www.joomlaworks.net/forum/k2-en/46416-solved-how-to-call-k2-viewed-item-s-title-creation-date#156871
I would prefer an override solution instead of using an additional extension.
I would like to render the following example via the K2 Content Override:
<?php echo $item->title; ?>
<?php echo $item->extraFields->bannerOne->value; ?>
<?php echo $this->item->tags[0]->link; ?>
Would you be able to assist me with cut & paste solution.
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
bnrjoomla.com/forums/posts/f2/t16/k2-bnr-nonfunctional-since-update-to-k2-2-7.html
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
Copy paste yes.
Actually the code seems correct, apart from the
$this->item->tags[0]->link;
where this should be used instead
$item->tags[0]->link;
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
Perhaps I did not property present my need.
I want to use a K2 Content Module override to display the title, specific tag(s), and specific extra field(s) of the current item being viewed.
The following sample K2 Content Module override code does not render the desired content for the current item being viewed.
<?php
// no direct access
defined('_JEXEC') or die;
?>
<?php echo $item->title; ?>
<?php echo $item->extraFields->bannerOne->value; ?>
<?php echo $item->tags[0]->link; ?>
<?php echo $item->tags[0]->link; ?>
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
I'll look into a solution. It is not that simple.
Furthermore I think this should be done as a PHP standalone module.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
Do you mean PHP standalone module, as in not a K2 Content Module?
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
gist.github.com/kricore/1e7ecf5ffdad017e547c
I 'll work on a solution.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
Please Log in or Create an account to join the conversation.
- Lefteris
-
- Offline
- Moderator
- Posts: 8743
Ideally this kind of functionality fits better in a plugin, but the module with disabled caching should do the trick.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Fábio Jordan
-
- Offline
- Senior Member
- Nothing like a good coffee to make a better web
Actually, the BNR Content for K2 works fine in K2 2.7. I'm using it with no problem.
If you need assistance with that module, let me know. See examples of how I'm using it:
www.cafecomfilme.com.br/filmes/caes-de-guerra
www.cafecomfilme.com.br/filmes/o-sono-da-morte
Best luck!
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
Please provide details on how you're using BNR Content for K2 for your website?
An annotated screenshot would be awesome :)
Please Log in or Create an account to join the conversation.
- Fábio Jordan
-
- Offline
- Senior Member
- Nothing like a good coffee to make a better web
So, what I've done is to insert two modules with BNR in differents positions (both are above the content).
In one module, I just call an extrafield (image type) to insert a background (and use fixed position in the DIV), like this:
<?php if($item->extraFields->NAMEOFEXTRAFIELD->value): ?>
<div>
<?php echo $item->extraFields->NAMEOFEXTRAFIELD->value ?>
</div>
<?php endif; ?>
In another, I call the other parameters, like this:
<?php if($params->get('bnrItemTitle')): ?>
<div class="itemTitleTopo">
<?php echo strstr($item->title, '|', true) ?: $item->title ?>
</div>
<?php endif; ?>
BNR has some specifics codes for title, image of item and other fields, but extrafields works pretty fine.
Just to let you know, I'm using K2 2.7, so I don't know if it works with 2.7.1
Best luck!
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
Here's an example:
Invalid consumer key/secret in configuration
Also, have you ever communicated with the developer of the BNR module?
Posted 2.7 Issue:
bnrjoomla.com/forums/posts/f2/t16/k2-bnr-nonfunctional-since-update-to-k2-2-7.html
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
<?php
/**
* @version 1.0
* @package Get the current item's data
* @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
// imports
require_once (JPATH_SITE.'/components/com_k2/helpers/route.php');
require_once (JPATH_SITE.'/components/com_k2/helpers/utilities.php');
// required params
$mainframe = JFactory::getApplication();
$db = JFactory::getDBO();
$user = JFactory::getUser();
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
// Execute only in a K2 item
if($option == 'com_k2' && $view == 'item')
{
// Get the current id
$itemid = JRequest::getInt('id');
// Perform the query
$query = "SELECT i.*, c.name AS categoryname,c.id AS categoryid, c.alias AS categoryalias, c.params AS categoryparams
FROM #__k2_items as i
LEFT JOIN #__k2_categories c ON c.id = i.catid
WHERE i.published = 1 ";
$query .= " AND i.access IN(".implode(',', $user->getAuthorisedViewLevels()).") ";
$query .= " AND i.id={$itemid}";
// Load the results
$db->setQuery($query);
$item = $db->loadObject();
// Load the model
$model = K2Model::getInstance('Item', 'K2Model');
// Building the object
// Build the object - tags
$tags = $model->getItemTags($item->id);
for ($i = 0; $i < sizeof($tags); $i++)
{
$tags[$i]->link = JRoute::_(K2HelperRoute::getTagRoute($tags[$i]->name));
}
$item->tags = $tags;
// Build the object - extrafields
$item->extra_fields = $model->getItemExtraFields($item->extra_fields, $item);
}
?>
<!-- Start the layout -->
<?php if($option == 'com_k2' && $view == 'item'): ?>
<!-- PASTE YOUR CODE HERE JOE -->
<?php endif; ?>
<!-- end -->
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
Thank you soooooo muchhhh - I just tested it (title, tag, and extra field) and it works perfectly.
This is how I feel right now...
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
If this is something that has some potential as a standalone module, let me know so I can create it.
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.
- Joe Campbell
-
Topic Author
- Offline
- Platinum Member
- Posts: 438
K2 Item Module
Add item content (title, tags, and extra fields) in any module position throughout a K2 page.
If so, would it ship with the K2 package, so in essence, users would receive three K2 module types:
mod_k2_tools
mod_k2_content
mod_k2_item
Please Log in or Create an account to join the conversation.
- Krikor Boghossian
-
- Offline
- Platinum Member
- Posts: 15920
JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)
Please Log in or Create an account to join the conversation.