1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Easiest PHP Help Ever! Take a Look!

Discussion in 'White Hat SEO' started by ramtripper, Mar 30, 2011.

Tags:
  1. ramtripper

    ramtripper BANNED BANNED

    Joined:
    Jul 31, 2010
    Messages:
    427
    Likes Received:
    273
    How do I make this function work without the "if" statement??

    <?php if(get_post_meta($post->ID, 'my_post_image', true)): ?>
    <img src="<?php echo get_post_meta($post->ID, 'my_post_image', true); ?>" alt=""/>
    <?php else: ?>

    <?php endif; ?>


    Omg, i will love you for helping me with this. I know it's simple, im just not too familiar with php..

    not exactly the same as excel.. LOL
     
  2. tukim

    tukim Regular Member

    Joined:
    Sep 20, 2009
    Messages:
    254
    Likes Received:
    173
    Location:
    localhost
    Looks like Wordpress, um tried removing "if" before (get_post_meta...?

    Then would need to remove <?php else: ?> assuming.

    First glance, not exactly sure. Back up before trying. I can't see related files and functions.

    EDIT: Could probaly remove first ( and last ) with my method also.
     
    Last edited: Mar 30, 2011
  3. wkrappen91

    wkrappen91 Power Member

    Joined:
    Sep 9, 2010
    Messages:
    588
    Likes Received:
    720
    Location:
    127.0.0.1
    i dont know what kind of php this is but i would try this:

    <img src="<?php echo get_post_meta($post->ID, 'my_post_image', true); ?>" alt=""/>
     
  4. tukim

    tukim Regular Member

    Joined:
    Sep 20, 2009
    Messages:
    254
    Likes Received:
    173
    Location:
    localhost
    This is what I mean, replace (after backing up) and try.

    <?php get_post_meta($post->ID, 'my_post_image', true): ?>
    <img src="<?php echo get_post_meta($post->ID, 'my_post_image', true); ?>" alt=""/>

    <?php endif; ?>
     
  5. wkrappen91

    wkrappen91 Power Member

    Joined:
    Sep 9, 2010
    Messages:
    588
    Likes Received:
    720
    Location:
    127.0.0.1
    No if = no endif...
    And i assume get_post_meta has a return value...
    PHP:
    <?php $pm=get_post_meta($post->ID'my_post_image'true); ?>
    <img src="<?php echo get_post_meta($post->ID'my_post_image'true); ?>" alt=""/>
     
  6. dummydecoy

    dummydecoy Junior Member

    Joined:
    Jul 4, 2010
    Messages:
    154
    Likes Received:
    39
    i havent try this yet..but

    <img src="<?=(get_post_meta($post->ID, 'my_post_image', true))?get_post_meta($post->ID, 'my_post_image', true):"otherimage.jpg"?>">
     
  7. tukim

    tukim Regular Member

    Joined:
    Sep 20, 2009
    Messages:
    254
    Likes Received:
    173
    Location:
    localhost
    Good point would result in a PHP error. Maybe removing endif would work, but heard that's a security issue in Wordpress? Unless in this case?

    I'm really not good with Wordpress...maybe wkrappen91 knows better.

    Which file is this even in Wordpress? We could see the code better as most would have it on our computers.

    EDIT: Maybe he already posted the solution.
     
    Last edited: Mar 30, 2011
  8. ramtripper

    ramtripper BANNED BANNED

    Joined:
    Jul 31, 2010
    Messages:
    427
    Likes Received:
    273
    wow, guys thanks a lot. I actually thought of a workaround for the theme im using.. it's really stupid they incorporated that piece in the theme, because it's supposed to be something like:

    "if" u dont have image for rotating featured images - the sample image (a blank 600 by 300) will be there - thus the "else"

    but I do have images - 4 of them in the featured area, and still the sample image shows up as a 5th.

    it linked to the portfolio page of my theme, so what i did was make a featured portfolio image in photoshop as the 5th image, and now it makes sense and works smoothly.

    Sorry for the trouble, but i really appreciate all your help guys!