Keyword

Custom K2 Content Module Assistance

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157647 by Joe Campbell
Custom K2 Content Module Assistance was created by Joe Campbell
I need assistance creating a K2 Content Module (override) that renders the current item title, tags and specific extra fields.

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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157648 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
I also see that the extension does not play nice with K2v2.7
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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 7 months ago #157651 by Krikor Boghossian
Replied by Krikor Boghossian on topic Custom K2 Content Module Assistance
Cut and paste no.
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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157655 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
That's for the correction - "Copy & Paste"

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 7 months ago - 8 years 7 months ago #157657 by Krikor Boghossian
Replied by Krikor Boghossian on topic Custom K2 Content Module Assistance
You would need to query the database in order to retrieve the data.
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 :)
Last edit: 8 years 7 months ago by Krikor Boghossian.

Please Log in or Create an account to join the conversation.

  • Joe Campbell
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157658 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
Ok - Thanks

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 7 months ago #157660 by Krikor Boghossian
Replied by Krikor Boghossian on topic Custom K2 Content Module Assistance
Yes, a new module would be better imo.

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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157661 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
Ok - any assistance would be much appreciated :)

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 7 months ago #157662 by Krikor Boghossian
Replied by Krikor Boghossian on topic Custom K2 Content Module Assistance
A similar concept exists here:
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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157663 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
Gratitude :)

Please Log in or Create an account to join the conversation.

More
8 years 7 months ago #157664 by Lefteris
Replied by Lefteris on topic Custom K2 Content Module Assistance
The code that Krikor provided should work fine. Just remember that the caching module should be disabled, if you want this to work properly.

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
  • Fábio Jordan's Avatar
  • Offline
  • Senior Member
  • Nothing like a good coffee to make a better web
More
8 years 7 months ago #157666 by Fábio Jordan
Replied by Fábio Jordan on topic Custom K2 Content Module Assistance
Hi Joe Campbell.

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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157669 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
Hi @FábioJordan your K2 looks very nice.

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
  • Fábio Jordan's Avatar
  • Offline
  • Senior Member
  • Nothing like a good coffee to make a better web
More
8 years 7 months ago #157671 by Fábio Jordan
Replied by Fábio Jordan on topic Custom K2 Content Module Assistance
Hi Joe Campbell.

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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157673 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
Thanks @FábioJordan please send me your company's Twitter handle, as I would like to feature the site.

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 7 months ago #157674 by Krikor Boghossian
Replied by Krikor Boghossian on topic Custom K2 Content Module Assistance
Here you go mate:
<?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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157679 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
Krikor, you are THE MAN!!!

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 7 months ago #157680 by Krikor Boghossian
Replied by Krikor Boghossian on topic Custom K2 Content Module Assistance
You 're welcome Joe :)

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
  • Joe Campbell's Avatar Topic Author
  • Offline
  • Platinum Member
More
8 years 7 months ago #157682 by Joe Campbell
Replied by Joe Campbell on topic Custom K2 Content Module Assistance
Are you talking about offering a:

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
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
8 years 7 months ago #157683 by Krikor Boghossian
Replied by Krikor Boghossian on topic Custom K2 Content Module Assistance
Actually I was thinking of a free module which could display any data of the current module in a module position with show/hide params.

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum