• Register or
  • Sign In
    • Forgot your password?
    • Forgot your username?
    Or sign in with your account on:
    Facebook
    Twitter
    Google
    LinkedIn

K2 | The powerful content extension for Joomla! developed by JoomlaWorks

  • home
  • about
  • blog
  • documentation
  • extend K2
  • showcase
  • community
  • demo
The 'de facto' content solution for Joomla! professionals!
  • Index
  • Recent Topics
  • Search
Welcome, Guest

To post messages, you need to login first.
K2 Community Forum
K2 Community Forum
New to K2? Ask here first!

PHP if statement with image extra field
(1 viewing) (1) Guest
Reply Topic
New Topic
  • Page:
  • 1

TOPIC: PHP if statement with image extra field

PHP if statement with image extra field 2 months, 2 weeks ago #170161

  • David Blane
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
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:

 
<?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!
Last Edit: 2 months, 2 weeks ago by David Blane. Reason: straighten up for viewing
Reply Quote

Re: PHP if statement with image extra field 2 months, 2 weeks ago #170168

  • William White
  • ( Moderator )
  • OFFLINE
  • Moderator
  • Posts: 3551
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
For better answers, please include urls to your live site.
williamwhitejr.com/index.php/k2-support/...it-a-support-request
Reply Quote

Re: PHP if statement with image extra field 2 months, 2 weeks ago #170209

  • David Blane
  • ( User )
  • OFFLINE
  • Fresh Boarder
  • Posts: 2
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
Reply Quote
Reply Topic
New Topic
  • Page:
  • 1
K2 Community Forum
K2 Community Forum
New to K2? Ask here first!
Find this topic helpful? Why not share it with others?
Tweet
Powered by Kunena
Time to create page: 0.17 seconds
Advertisement
  • Contact us
  • Join the K2 Expert Companies list
  • Privacy Policy
back to top
Copyright © 2006 - 2013 JoomlaWorks Ltd.. All rights reserved. K2 is a joint project by JoomlaWorks Ltd. & Nuevvo Webware Ltd., released under the GNU/GPL v2 license.
Joomla! is a registered trademark of Open Source Matters, Inc. JoomlaWorks/Nuevvo are not affiliated with or endorsed by Open Source Matters or the Joomla! Project.
designed by Nuevvo