Keyword

Display extra fields in BT-Content-Slider (module)

  • Justin Thomas
  • Justin Thomas's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 8 months ago #62151 by Justin Thomas
I have posted the following on the BT-Content-Slider forum as well. However I feel the piece I am missing is more to do with K2 and me not understanding how to call the field into the module.

I have used the following code in the category_item.php file with success, but when taken to this 3rd party module then it does not work.
<?php if($this->item->params->get('catItemExtraFields') && count($this->item->extra_fields)): ?>
	  <!-- Item extra fields -->
	  <div class="catItemExtraFields">
<?php $custom = $this->item->extra_fields; ?>
	  	<ul>
			<li>
				<span style="font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;font-weight: normal;font-size:11px;"><?php echo ($custom[0]->type=='date')?JHTML::_('date', $custom[0]->value, JText::_('K2_DATE_FORMAT_LC')):$custom[0]->value; ?> from <?php echo $custom[1]->value; ?></span>
			</li>
			</ul>	    <div class="clr"></div>
	  </div>
	  <?php endif; ?>

So, where am I going wrong? I have looked at a lot of forum entries "nearly" describing this, but no answer. I really hope somebody has succeeded at something like this and can help me.

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

More
12 years 8 months ago #62152 by Adam L
Hey Justin -- I'm getting down and dirty with the extra fields myself in learning K2 (the extra fields are the exact usage scenario I'm investigating K2 for!)

Very simple question... can you verify that for this item, Extra Field [0] and Extra Field [1] both exist as items (and that [0] is a date type)?

As I'm troubleshooting this, I've found that a quick hack-and-slash way to see what I'm doing wrong is to iterate through all the extra fields and only process ones based on the text value of the field name ($myfields->name).

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

More
12 years 8 months ago #62153 by william white
Replied by william white on topic Re: Display extra fields in BT-Content-Slider (module)
@justin try echo $custom[1]->value
@adam [0] is the first element of the array or first extra field and [1] is the second element of the array or the second extra field

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

  • Justin Thomas
  • Justin Thomas's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 8 months ago #62154 by Justin Thomas
Replied by Justin Thomas on topic Re: Display extra fields in BT-Content-Slider (module)

Adam L wrote: Hey Justin -- I'm getting down and dirty with the extra fields myself in learning K2 (the extra fields are the exact usage scenario I'm investigating K2 for!)

Very simple question... can you verify that for this item, Extra Field [0] and Extra Field [1] both exist as items (and that [0] is a date type)?

As I'm troubleshooting this, I've found that a quick hack-and-slash way to see what I'm doing wrong is to iterate through all the extra fields and only process ones based on the text value of the field name ($myfields->name).


Thank you for your reply. Both Extra Field [0] and Extra Field [1] exist and [0] is a date type. I don't think there is any issue with the call but there is something else missing. I have used this call in the category_item.php file and it has worked fine, but when I move it into the BT-Content-Slider module being called using
{loadposition "name here"}

it doesn't work. There must be something in the headers in category_item that I am not including in my header for the default.php file for BT-Content-Slider.

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

  • Justin Thomas
  • Justin Thomas's Avatar Topic Author
  • Offline
  • Senior Member
More
12 years 8 months ago #62155 by Justin Thomas
Replied by Justin Thomas on topic Re: Display extra fields in BT-Content-Slider (module)

William White wrote: @justin try echo $custom[1]->value
@adam [0] is the first element of the array or first extra field and [1] is the second element of the array or the second extra field


William, thank you for your reply. As you will note in my original post I am using
<span style="font-family: 'Trebuchet MS', Arial, Helvetica, sans-serif;font-weight: normal;font-size:11px;"><?php echo ($custom[0]->type=='date')?JHTML::_('date', $custom[0]->value, JText::_('K2_DATE_FORMAT_LC')):$custom[0]->value; ?> from <?php echo $custom[1]->value; ?></span>

In the body of default.php so I have the call you suggest (and a more defined call for the date with custom[0]. This call works perfectly in category_item.php but does not work in BT-Content-Slider when loaded in a
{loadposition}

call. There is no option in the BT-Content-Slider to request the extra fields, so is there something I can put into the default.php header that will request this data so that I can call it in the <body>?

Thanks again.

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

  • Agence culturelle départementale Dordogne-Périgord
  • Agence culturelle départementale Dordogne-Périgord's Avatar
  • Offline
  • Junior Member
More
10 years 7 months ago #62156 by Agence culturelle départementale Dordogne-Périgord
Replied by Agence culturelle départementale Dordogne-Périgord on topic Re: Display extra fields in BT-Content-Slider (module)
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 !

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


Powered by Kunena Forum