felix

Show K2 Extra Fields

6 posts in this topic

Hi,

I need to show the k2 extra fields in BT Content Slider. How can I do this? Pls help!!

I know that this extension does not have that functionality, but some little hack maybe, thanks :)

Share this post


Link to post
Share on other sites

Hi guy

I can only give you my advice. I guess you know PHP. So you can open file mod_bt_contentslider/classes/k2.php, you will see we built query to get k2 item at here ( function getList) you can customize it to get extra fields of items.

Then in /tmpl/default.php ( and imgalign.php with old version) you should be check if extra fields are available, you can echo it with some HTML tags.

I hope this lines will help you.

Regards

Share this post


Link to post
Share on other sites

OK, I got it working the way I wanted it to.

I wanted to replace intro / full text with an extrafield that I called 'Accroche' . This extrafield has an ID of 132 (useful to know the ID that will be used in code below).

We will be editing 2 files :

/modules/mod_bt_contentslider/classes/content.php

and

/modules/mod_bt_contentslider/classes/k2.php

First thing to do is get the extrafield info from database :

in /modules/mod_bt_contentslider/classes/content.php (around line 77) I added a.extra_fields, as follows

 $model->setState('list.select', 'a.urls, a.images, a.fulltext, a.id, a.title, a.alias, a.introtext, a.extra_fields, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured,' . ' LENGTH(a.fulltext) AS readmore');

Save file & close

Now lets get to /modules/mod_bt_contentslider/classes/k2.php (around line 234),

Replace this original code



// cut introtext
if ($limitDescriptionBy == 'word') {

$item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);

$item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);

}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));

// get author name & link

With this code that I've commented to make things understandable for noobs like me ;)



// REPLACE intro/full text With extra-field info
$extras = json_decode($item->extra_fields); // JSON Array we'll call extras (note final 's' : not to confuse with below variable)
foreach ($extras as $key=>$extraField): //Get values from array
if($extraField->value != ''): //If not empty
if($extraField->id == '132'): // This is ID value for extrafield I want to show --- Search your K2 extrafield's id in Joomla backoffice ->K2 ->extrafields ---
if($extraField->value != ''): // If there's content in the extrafield of that ID
$extra = $extraField->value; //Give $extra that value so we can hand it down below
endif;
endif;
endif;
endforeach;

// cut introtext
if ($limitDescriptionBy == 'word') {

// $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substrword($extra, $maxDesciption, $replacer, $isStrips, $stringtags);
} else {

// $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($extra, $maxDesciption, $replacer, $isStrips, $stringtags) ;

}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));

// get author name & link

As you can see, I've commented out the intro texts as I don't want them. You can modify that if you want both introtext AND extrafield.

Hope this helps.

Cheers !

Share this post


Link to post
Share on other sites

OK, I got it working the way I wanted it to.

I wanted to replace intro / full text with an extrafield that I called 'Accroche' . This extrafield has an ID of 132 (useful to know the ID that will be used in code below).

We will be editing 2 files :

/modules/mod_bt_contentslider/classes/content.php

and

/modules/mod_bt_contentslider/classes/k2.php

First thing to do is get the extrafield info from database :

in /modules/mod_bt_contentslider/classes/content.php (around line 77) I added a.extra_fields, as follows

 $model->setState('list.select', 'a.urls, a.images, a.fulltext, a.id, a.title, a.alias, a.introtext, a.extra_fields, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured,' . ' LENGTH(a.fulltext) AS readmore');

Save file & close

Now lets get to /modules/mod_bt_contentslider/classes/k2.php (around line 234),

Replace this original code



// cut introtext
if ($limitDescriptionBy == 'word') {

$item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);

$item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);

}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));

// get author name & link

With this code that I've commented to make things understandable for noobs like me ;)



// REPLACE intro/full text With extra-field info
$extras = json_decode($item->extra_fields); // JSON Array we'll call extras (note final 's' : not to confuse with below variable)
foreach ($extras as $key=>$extraField): //Get values from array
if($extraField->value != ''): //If not empty
if($extraField->id == '132'): // This is ID value for extrafield I want to show --- Search your K2 extrafield's id in Joomla backoffice ->K2 ->extrafields ---
if($extraField->value != ''): // If there's content in the extrafield of that ID
$extra = $extraField->value; //Give $extra that value so we can hand it down below
endif;
endif;
endif;
endforeach;

// cut introtext
if ($limitDescriptionBy == 'word') {

// $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substrword($extra, $maxDesciption, $replacer, $isStrips, $stringtags);
} else {

// $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($extra, $maxDesciption, $replacer, $isStrips, $stringtags) ;

}
$item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));

// get author name & link

As you can see, I've commented out the intro texts as I don't want them. You can modify that if you want both introtext AND extrafield.

Hope this helps.

Cheers !

tronghm and nothingkai like this

Share this post


Link to post
Share on other sites
On 2/19/2014 at 4:06 PM, Vincen said:

OK, I got it working the way I wanted it to.

I wanted to replace intro / full text with an extrafield that I called 'Accroche' . This extrafield has an ID of 132 (useful to know the ID that will be used in code below).

We will be editing 2 files :

/modules/mod_bt_contentslider/classes/content.php

and

/modules/mod_bt_contentslider/classes/k2.php

First thing to do is get the extrafield info from database :

in /modules/mod_bt_contentslider/classes/content.php (around line 77) I added a.extra_fields, as follows

 

 

 $model->setState('list.select', 'a.urls, a.images, a.fulltext, a.id, a.title, a.alias, a.introtext, a.extra_fields, a.state, a.catid, a.created, a.created_by, a.created_by_alias,' . ' a.modified, a.modified_by,a.publish_up, a.publish_down, a.attribs, a.metadata, a.metakey, a.metadesc, a.access,' . ' a.hits, a.featured,' . ' LENGTH(a.fulltext) AS readmore');

 

Save file & close

Now lets get to /modules/mod_bt_contentslider/classes/k2.php (around line 234),

Replace this original code

 

 


// cut introtext
            if ($limitDescriptionBy == 'word') {

                $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);

                $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);

            }
            $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));

// get author name & link

 

With this code that I've commented to make things understandable for noobs like me ;)

 

 


// REPLACE intro/full text With extra-field info
$extras = json_decode($item->extra_fields); // JSON Array we'll call extras (note final 's' : not to confuse with below variable)
foreach ($extras as $key=>$extraField): //Get values from array
if($extraField->value != ''):  //If not empty
if($extraField->id == '132'): // This is ID value for extrafield I want to show --- Search your K2 extrafield's id in Joomla backoffice ->K2 ->extrafields ---
if($extraField->value != ''): // If there's content in the extrafield of that ID 
$extra = $extraField->value; //Give $extra that value so we can hand it down below
endif; 
endif; 
endif; 
endforeach; 

// cut introtext
            if ($limitDescriptionBy == 'word') {

               // $item->description = self::substrword($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
                $item->description = self::substrword($extra, $maxDesciption, $replacer, $isStrips, $stringtags);
            } else {

               // $item->description = self::substring($item->introtext, $maxDesciption, $replacer, $isStrips, $stringtags);
$item->description = self::substring($extra, $maxDesciption, $replacer, $isStrips, $stringtags) ;

            }
            $item->categoryLink = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid . ':' . urlencode($item->categoryalias))));

// get author name & link

 

As you can see, I've commented out the intro texts as I don't want them. You can modify that if you want both introtext AND extrafield.

Hope this helps.

Cheers !

Dear bro,

 

Thanks for help, I edit same your code but it not show.

So we need add field show on mod_bt_contentslider.php ?

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now