COMMUNITY FORUM
Search Results (Searched for: PHP if statement with image extra field)
- JoomlaWorks
04 Jan 2019 01:55
Replied by JoomlaWorks on topic Extra Fields for registered users only
Extra Fields for registered users only
Category: English K2 Community
@Mazen Regarding your first question, are you referring to data submission or data display? If it's the latter, you can simply wrap the output of the extra field you want to hide in an if statement that checks user permissions.
As for your 2nd question, there are many ways to do this. The simplest though is with Simple Image Gallery Pro (www.joomlaworks.net/extensions/commercial/simple-image-gallery-pro) and some K2 item.php overrides to show the gallery first (in place of the main K2 image).
As for your 2nd question, there are many ways to do this. The simplest though is with Simple Image Gallery Pro (www.joomlaworks.net/extensions/commercial/simple-image-gallery-pro) and some K2 item.php overrides to show the gallery first (in place of the main K2 image).
- Kelsey Brookes
23 Oct 2017 12:20
Errors, missing extrafield data after update to 3.8.x was created by Kelsey Brookes
Errors, missing extrafield data after update to 3.8.x
Category: English K2 Community
Hi All,
Having some weird issues since updating to 3.8.x with K2 2.8, then 2.8.1.
I have a mod_k2_content module that picks 3 items at random from a category, grabs the title, link, introtext and an image extraField. It was working prior to updates. Now, it's not, but in a very odd way.
Here's the code.
It should output the data in three columns. Instead the first extraField element appears, then nothing else. Here's the live output.
Before you ask, every item in the category has a title, introtext and an image extrafield with data.
If I turn on error reporting, I get this:
Notice: Undefined property: stdClass::$extraFields in /home/propertyme/public_html/templates/frontend/html/mod_k2_content/feature-icons/default.php on line 20
You can see it appearing across all three rows.
www.dropbox.com/s/h0zal9fnk9tolyr/Screenshot%202017-10-23%2020.07.54.png?dl=0
What's super weird, is that if I remove all my conditional statements, except those to do with the loop, the output looks like this:
It's now pulling the first image, title, link and introtext, and all subsequent titles and links, but not subsequent images or introtexts.
It's really got me stumped and help would be appreciated!
Having some weird issues since updating to 3.8.x with K2 2.8, then 2.8.1.
I have a mod_k2_content module that picks 3 items at random from a category, grabs the title, link, introtext and an image extraField. It was working prior to updates. Now, it's not, but in a very odd way.
Here's the code.
<?php /** * @version 2.8.x * @package K2 * @author JoomlaWorks https://www.joomlaworks.net * @copyright Copyright (c) 2006 - 2017 JoomlaWorks Ltd. All rights reserved. * @license GNU/GPL license: http://www.gnu.org/copyleft/gpl.html */ // no direct access defined('_JEXEC') or die; ?> <div id="feature-icons-<?php echo $module->id; ?>" class="feature-icons"> <?php if(count($items)): ?> <div class="container-sm"> <div class="row"> <?php foreach ($items as $key=>$item): ?> <div class="col-sm-4 feature-icons__item text-center"> <?php if($item->extraFields->FeatureIcon->value !=''): ?> <a class="moduleItemTitle" href="<?php echo $item->link; ?>"> <?php echo $item->extraFields->FeatureIcon->value; ?> </a> <?php endif; ?> <?php if($params->get('itemTitle')): ?> <h4 class="feature-icons__item-title"><a href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a></h4> <?php endif; ?> <?php if($params->get('itemIntroText')): ?> <?php echo $item->introtext; ?> <?php endif; ?> </div> <?php endforeach; ?> </div> </div> <?php endif; ?> </div>
It should output the data in three columns. Instead the first extraField element appears, then nothing else. Here's the live output.
<div id="feature-icons-116" class="feature-icons"> <div class="container-sm"> <div class="row"> <div class="col-sm-4 feature-icons__item text-center"> <a class="moduleItemTitle" href="/features/property-accounting/reconciliation"> <img src="/images/features/icons/icon-reconciliation.png" alt="Feature Icon"> </a> </div> <div class="col-sm-4 feature-icons__item text-center"> </div> <div class="col-sm-4 feature-icons__item text-center"> </div> </div> </div> </div>
Before you ask, every item in the category has a title, introtext and an image extrafield with data.
If I turn on error reporting, I get this:
Notice: Undefined property: stdClass::$extraFields in /home/propertyme/public_html/templates/frontend/html/mod_k2_content/feature-icons/default.php on line 20
You can see it appearing across all three rows.
www.dropbox.com/s/h0zal9fnk9tolyr/Screenshot%202017-10-23%2020.07.54.png?dl=0
What's super weird, is that if I remove all my conditional statements, except those to do with the loop, the output looks like this:
<div id="feature-icons-116" class="feature-icons"> <div class="container-sm"> <div class="row"> <div class="col-sm-4 feature-icons__item text-center"> <a class="moduleItemTitle" href="/features/service-support/support"> <img src="/images/features/icons/icon-support.png" alt="Feature Icon"> </a> <h4 class="feature-icons__item-title"><a href="/features/service-support/support">Support</a></h4> <p>Knowledge base and support forum, with video tutorials and getting started guides.</p> </div> <div class="col-sm-4 feature-icons__item text-center"> <a class="moduleItemTitle" href="/features/service-support/data-migration"> </a> <h4 class="feature-icons__item-title"><a href="/features/service-support/data-migration">Data Migration</a></h4> </div> <div class="col-sm-4 feature-icons__item text-center"> <a class="moduleItemTitle" href="/features/property-management/client-view"> </a> <h4 class="feature-icons__item-title"><a href="/features/property-management/client-view">Client View</a></h4> </div> </div> </div> </div>
It's now pulling the first image, title, link and introtext, and all subsequent titles and links, but not subsequent images or introtexts.
It's really got me stumped and help would be appreciated!
- hristo
24 Nov 2014 14:29 - 24 Nov 2014 19:37
Replied by hristo on topic change display order of images? and remove filename..
change display order of images? and remove filename..
Category: Simple Image Gallery
Hi. This last post didn't work /mby its old and there have been updates/ but it was very helpfull. I'm not a coder, but with some luck and most by guessing I got sucsess. I made it possible to change pics name.. Also when upload new pics in empty gallery they are named 01.jpg 02.jpg and etc. Then if u upload new pics in same gallery it checks the number of files in DIR and also checks the max number of file in DIR and starts the new uploaded image count from the biggest+1 of these two.. i did this to prevent overwriting of images.. if some pics are deleted, or some pics have text names.. couse u can change them with A, B, C if u want...
Here are my changes: /make backup.. i'm not PRO and can't guarantee/
Edit in administrator/components/com_sigpro/controllers/gallery.php, in public function save(), you will see a bunch of set state statements...add lines
Then, in administrator/components/com_sigpro/models/gallery.php, around line 114, in public function upload(), before the line $result = JFile::upload($file, $path.'/'.$folder.'/'.JFile::makeSafe($filename)); add this:Important.. only for uploading JPG pictures.. ned some changes if u want to upload diferent types of images.
In same file some lines down is public function save().. here in function add:
and also some lines down replace the whole foreach ($files as $key => $file) with:
In administrator/com_sigpro/views/gallery/tmpl/default.php, you'll see the spot where you can edit the image descript. and title...add this over title field:I use pathinfo to get rid of .jpg and so i cant accidently delete image type which removes it from gallery - we add this .jpg in public save function.
And finaly in same file.. some lines down.. we need to ad the Filename field also for the fresh uploaded pics. Again over title field add thisHere i could not remove .jpg from file name, but i didnt try much because if u refresh page or hit save button it removes .jpg and then u can easyly rearenge files....
Many thanks to Matthew Cowan
Sorry if my english or code language is bad!
Hope i didnt forgot some line :) .. ..
And agan i'm not a coder, and there are mby lots of mistakes.. so make backups befor u try it.. or if u can rewrite it and post it here.. it works for me great for the moment :)
Ops.. i found BUG.. reordering not working corectly.. Pictures was overriding one another.. it was logical :) so I add unique random key to file name separated by "-" so i can extract and show from filename only the number infront. Code is fixed.. .
Here are my changes: /make backup.. i'm not PRO and can't guarantee/
Edit in administrator/components/com_sigpro/controllers/gallery.php, in public function save(), you will see a bunch of set state statements...add lines
$newfilenames = JRequest::getVar('newfilenames'); $model->setState('newfilenames', $newfilenames);
Then, in administrator/components/com_sigpro/models/gallery.php, around line 114, in public function upload(), before the line $result = JFile::upload($file, $path.'/'.$folder.'/'.JFile::makeSafe($filename)); add this:
$max = 0; $directory = $path.'/'.$folder.'/'; if (($dir = opendir($directory)) !== false) { while (($filenam = readdir($dir)) !== false) { $int = intval(basename($filenam)); if ($int > $max) { $max= $int; } } closedir($dir); } $filecount = count(glob($directory . "*")); $filename = $max + 1; if ($filecount>$filename ) {$filename = $filecount;} if(strlen($filename)==1){$filename="0".$filename;} $filename .=".jpg";
In same file some lines down is public function save().. here in function add:
$newfilenames= $this->getState('newfilenames');
and also some lines down replace the whole foreach ($files as $key => $file) with:
foreach ($files as $key => $file){ if ($newfilenames[$key] != strtok(pathinfo($file, PATHINFO_FILENAME), '-') ) { if(strlen($newfilenames[$key])==1){$newfilenames[$key]="0".$newfilenames[$key];} $character_array = array_merge(range(a, z), range(0, 9)); $string = ""; for($i = 0; $i < 6; $i++) { $string .= $character_array[rand(0, (count($character_array) - 1))]; } $newfilenames[$key] .= "-" .$string; rename($path.'/'.$folder.'/'.$file, $path.'/'.$folder.'/'.$newfilenames[$key].'.jpg' ); } }
In administrator/com_sigpro/views/gallery/tmpl/default.php, you'll see the spot where you can edit the image descript. and title...add this over title field:
<label>Filename</label> <input type="text" name="newfilenames[]" value="<?php echo intval(strtok(pathinfo($image->name, PATHINFO_FILENAME), '-'));
And finaly in same file.. some lines down.. we need to ad the Filename field also for the fresh uploaded pics. Again over title field add this
<label>Filename</label> <input type="text" class="sigProFilename" name="newfilenames[]" value=""/>
Many thanks to Matthew Cowan
Sorry if my english or code language is bad!
Hope i didnt forgot some line :) .. ..
And agan i'm not a coder, and there are mby lots of mistakes.. so make backups befor u try it.. or if u can rewrite it and post it here.. it works for me great for the moment :)
Ops.. i found BUG.. reordering not working corectly.. Pictures was overriding one another.. it was logical :) so I add unique random key to file name separated by "-" so i can extract and show from filename only the number infront. Code is fixed.. .
- Krikor Boghossian
14 Jul 2014 13:58
Replied by Krikor Boghossian on topic Djs page
Djs page
Category: Commercial Joomla Templates
That is a tricky question.
By default no. K2 does not have a seperate image in listings and items. However if you have some basic coding skills you can achieve this.
What you need to do is:
a) Create a new image-type extrafield for the DJ's (Producer Additional Info group)
b) Read this post on how to render specific extrafields.
getk2.org/community/English-K2-Community/171284-Where-to-edit-K2-after-Item-Fields
c) Backup and open the item.php file located in templates/radiowave/html/com_k2/grid .
Now: replace the following block of code:
With the code for the extrafield. Some CSS tweaking might be needed. Furthermore you can also replace the if statements for the image with ones that correspond with the extrafield.
By default no. K2 does not have a seperate image in listings and items. However if you have some basic coding skills you can achieve this.
What you need to do is:
a) Create a new image-type extrafield for the DJ's (Producer Additional Info group)
b) Read this post on how to render specific extrafields.
getk2.org/community/English-K2-Community/171284-Where-to-edit-K2-after-Item-Fields
c) Backup and open the item.php file located in templates/radiowave/html/com_k2/grid .
Now: replace the following block of code:
<a class="modal" rel="{handler: 'image'}" href="<?php echo $this->item->imageXLarge; ?>" title="<?php echo JText::_('K2_CLICK_TO_PREVIEW_IMAGE'); ?>"> <?php /* <img src="<?php echo $this->item->image; ?>" alt="<?php if(!empty($this->item->image_caption)) echo K2HelperUtilities::cleanHtml($this->item->image_caption); else echo K2HelperUtilities::cleanHtml($this->item->title); ?>" style="width:<?php echo $this->item->imageWidth; ?>px; height:auto;" /> */?> <span style="background-image:url(<?php echo $this->item->image; ?>);"></span> </a>
With the code for the extrafield. Some CSS tweaking might be needed. Furthermore you can also replace the if statements for the image with ones that correspond with the extrafield.
- David Blane
06 Mar 2013 16:42
Replied by David Blane on topic PHP if statement with image extra field
PHP if statement with image extra field
Category: English K2 Community
Apologies,
I am using K2 Version 2.6.5
and Joomla 2.5.9
Thanks for pointing me to the new syntax. That helps me for the most part.
Although, we would really like to be able to write the Extra Field ID Number and NOT the alias, if possible.
I have not been able to figure it out, what are your thoughts?
Thanks
I am using K2 Version 2.6.5
and Joomla 2.5.9
Thanks for pointing me to the new syntax. That helps me for the most part.
Although, we would really like to be able to write the Extra Field ID Number and NOT the alias, if possible.
I have not been able to figure it out, what are your thoughts?
Thanks
- william white
06 Mar 2013 01:37
Replied by william white on topic PHP if statement with image extra field
PHP if statement with image extra field
Category: English K2 Community
You dont mention versions of j or k2.
If using newer version of k2 i would try using the syntax described in this blog post
getk2.org/blog/1068-k2-v262-now-available
If using newer version of k2 i would try using the syntax described in this blog post
getk2.org/blog/1068-k2-v262-now-available
- David Blane
05 Mar 2013 19:27 - 05 Mar 2013 19:28
PHP if statement with image extra field was created by David Blane
PHP if statement with image extra field
Category: English K2 Community
I'm trying to display a <div> only if the image extra field is being used. if it is not being used, do not show the <div>
The code looks like this right now:
The problem is the $extrafields variable is never empty it either displays
<img alt="Interviewer Image" src="/"> -- NO IMAGE
or
<img alt="Interviewer Image" src=".../image.png"> -- With An Image
So our PHP statement does not really do anything since the $extrafield variable is never empty.
How can I get this PHP code to work?
Thanks!
The code looks like this right now:
<?php if(isset($extrafields['3']) === true && empty($extrafields['3']) === false): ?> <div class="interview-image-block"> <?php echo $extrafields[3];?> <div class="interview-caption"> <?php echo $extrafields[7];?> </div> </div> <?php endif; ?>
The problem is the $extrafields variable is never empty it either displays
<img alt="Interviewer Image" src="/"> -- NO IMAGE
or
<img alt="Interviewer Image" src=".../image.png"> -- With An Image
So our PHP statement does not really do anything since the $extrafield variable is never empty.
How can I get this PHP code to work?
Thanks!
- Peter Grube
13 Dec 2012 03:16
Replied by Peter Grube on topic Problem with Image Extra Field
Problem with Image Extra Field
Category: English K2 Community
Hi everyone,
I figured out a work around for this, I thought I might share to help anyone else having same problem, is simple just add a if , else statement to code like so.
Displaying 1 - 11 out of 11 results.
I figured out a work around for this, I thought I might share to help anyone else having same problem, is simple just add a if , else statement to code like so.
- Nick

09 Feb 2012 14:14 Tutorial: Show placeholder image for item was created by Nick Tutorial: Show placeholder image for item
Category: English K2 Community
So I'm running an anime site with K2 and I have placeholder images saying "coming-soon" when the screenshot has not been uploaded yet. I thought why not share my code for that.
It's actually really easy.
First you need to open up the item.php model which can be found in /components/com_k2/models/item.php
Scroll down to line 118 and you'll see a block of code with a bunch of "if" statements. Select that block (from 118 to 159 (right before it says //extra fields) and delete it.
Replace that with this code found here:
pastebin.com/SzGWTbfX
Now all you need to do is change the "coming-soon" part to whatever you want. The images should be stored in the /images/ folder in the joomla root.
In my case i just have a small version and a large version. I don't need any other sizes. You can obviously change that ;)
Question? Ask!
- d.k.shukla
31 Jan 2010 17:53
Replied by d.k.shukla on topic Search K2 Problem
Search K2 Problem
Category: English K2 Community
Hi
I would like to share my other experience about full text search with latest K2 ver 2.2, it is working fine without any error at my local machine. My local system information is following.
PHP Built on: Linux 2.6.32-ARCH #1 SMP PREEMPT Thu Jan 7 22:28:29 CET 2010 x86_64
Database Version: 5.1.42
Database Collation: utf8_general_ci
PHP Version: 5.3.1
Web Server: Apache/2.2.14 (Unix) PHP/5.3.1 with Suhosin-Patch Phusion_Passenger/2.2.2
Web Server to PHP interface: apache2handler
Joomla! Version: Joomla! 1.5.15 Stable [ Wojmamni Ama Mamni ] 05-November-2009 04:00 GMT
User Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.7) Gecko/20100105 Shiretoko/3.5.7
After doing this test it seems that error is coming due to Mysql version but I am not sure.
I hope somebody will fix this error or express their views on this behaviour.
Shukla
Stephen Robb said:I am having the same problem. The issues seems to be with the SELECT statement, and specifically the "MATCH AGAINST" clause. I'm no SQL admin, but I can extract the query K2 is sending using debug mode and edit the query to work using LIKE, but I can't get it to work with the MATCH construct. Note that the exact match option uses "BOOLEAN MODE" in the match, and this seems to work for me too.
To me it looks like K2 is creating some invalid SQL.
This works (i.e. returns rows) where search string is found:
SELECT * FROM jos_k2_items as i WHERE MATCH(i.title, i.introtext, i.`fulltext`,i.extra_fields_search,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.metadesc,i.metakey) AGAINST ('"searchstring"' IN BOOLEAN MODE)
This doesn't work (i.e. returns no rows, neither in Joomla or in phpMyAdmin):
SELECT * FROM jos_k2_items as i WHERE
MATCH(i.title, i.introtext, i.`fulltext`,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.extra_fields_search,i.metadesc,i.metakey) AGAINST ('searchsrring')
I would like to share my other experience about full text search with latest K2 ver 2.2, it is working fine without any error at my local machine. My local system information is following.
PHP Built on: Linux 2.6.32-ARCH #1 SMP PREEMPT Thu Jan 7 22:28:29 CET 2010 x86_64
Database Version: 5.1.42
Database Collation: utf8_general_ci
PHP Version: 5.3.1
Web Server: Apache/2.2.14 (Unix) PHP/5.3.1 with Suhosin-Patch Phusion_Passenger/2.2.2
Web Server to PHP interface: apache2handler
Joomla! Version: Joomla! 1.5.15 Stable [ Wojmamni Ama Mamni ] 05-November-2009 04:00 GMT
User Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.7) Gecko/20100105 Shiretoko/3.5.7
After doing this test it seems that error is coming due to Mysql version but I am not sure.
I hope somebody will fix this error or express their views on this behaviour.
Shukla
Stephen Robb said:I am having the same problem. The issues seems to be with the SELECT statement, and specifically the "MATCH AGAINST" clause. I'm no SQL admin, but I can extract the query K2 is sending using debug mode and edit the query to work using LIKE, but I can't get it to work with the MATCH construct. Note that the exact match option uses "BOOLEAN MODE" in the match, and this seems to work for me too.
To me it looks like K2 is creating some invalid SQL.
This works (i.e. returns rows) where search string is found:
SELECT * FROM jos_k2_items as i WHERE MATCH(i.title, i.introtext, i.`fulltext`,i.extra_fields_search,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.metadesc,i.metakey) AGAINST ('"searchstring"' IN BOOLEAN MODE)
This doesn't work (i.e. returns no rows, neither in Joomla or in phpMyAdmin):
SELECT * FROM jos_k2_items as i WHERE
MATCH(i.title, i.introtext, i.`fulltext`,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.extra_fields_search,i.metadesc,i.metakey) AGAINST ('searchsrring')
- Stephen Robb
31 Jan 2010 10:42
Replied by Stephen Robb on topic Search K2 Problem
Search K2 Problem
Category: English K2 Community
I am having the same problem. The issues seems to be with the SELECT statement, and specifically the "MATCH AGAINST" clause. I'm no SQL admin, but I can extract the query K2 is sending using debug mode and edit the query to work using LIKE, but I can't get it to work with the MATCH construct. Note that the exact match option uses "BOOLEAN MODE" in the match, and this seems to work for me too.
To me it looks like K2 is creating some invalid SQL.
This works (i.e. returns rows) where search string is found:
SELECT * FROM jos_k2_items as i WHERE MATCH(i.title, i.introtext, i.`fulltext`,i.extra_fields_search,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.metadesc,i.metakey) AGAINST ('"searchstring"' IN BOOLEAN MODE)
This doesn't work (i.e. returns no rows, neither in Joomla or in phpMyAdmin):
SELECT * FROM jos_k2_items as i WHERE
MATCH(i.title, i.introtext, i.`fulltext`,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.extra_fields_search,i.metadesc,i.metakey) AGAINST ('searchsrring')
To me it looks like K2 is creating some invalid SQL.
This works (i.e. returns rows) where search string is found:
SELECT * FROM jos_k2_items as i WHERE MATCH(i.title, i.introtext, i.`fulltext`,i.extra_fields_search,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.metadesc,i.metakey) AGAINST ('"searchstring"' IN BOOLEAN MODE)
This doesn't work (i.e. returns no rows, neither in Joomla or in phpMyAdmin):
SELECT * FROM jos_k2_items as i WHERE
MATCH(i.title, i.introtext, i.`fulltext`,i.image_caption,i.image_credits,i.video_caption,i.video_credits,i.extra_fields_search,i.metadesc,i.metakey) AGAINST ('searchsrring')