65 posts
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
PurpleNinja says

I want a code that it will show the original photo of the featured image when when the “x” field is empty, and if it isn’t then it will not shot the featured image.

At another point of the single post I want to show the “x” when it not empty, and it’s empty then it will show nothing.

Also, the “x” field must support the display of shortcodes (example: A gallery of nextgen with shortcode), embed tweet and Instagram photos.

I have created this code ( http://pastebin.com/thQkStqQ ) that I show on the place of the featured image the “x” field when it has a record inside but I have problems with tit and it doesn’t tweet and Instagram photos. It also has conflicts with the shortcodes.

Can someone help me with those 2 codes so I can make them work right?

1455 posts How's the surf doing?
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Had an item featured on Envato Market
  • Made it to the Authors' Hall of Fame
+6 more
tommusrhodus says

The variable $short is completely undefined in your code, shouldn’t $short be $myfield?


<?php
$myfield= get_post_meta($post->ID, 'short', true);
//Checking if anything exists for the key short
if ($myfield) { ?>
<?php echo do_shortcode($myfield); ?>
<?php } //if there is nothing for short then display
else { ?>
<?php the_post_thumbnail(); ?>
<?php } ?>

Also, a little cleaner PHP:


<?php
    $myfield = get_post_meta($post->ID, 'short', true);

    /**
     * Checking if anything exists for the key short
     */
    if( $myfield ) {
        echo do_shortcode( $myfield );
    } else { 
        the_post_thumbnail();
    } 
?>
65 posts
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
PurpleNinja says

The variable $short is completely undefined in your code, shouldn’t $short be $myfield?

<?php
$myfield= get_post_meta($post->ID, 'short', true);
//Checking if anything exists for the key short
if ($myfield) { ?>
<?php echo do_shortcode($myfield); ?>
<?php } //if there is nothing for short then display
else { ?>
<?php the_post_thumbnail(); ?>
<?php } ?>

Also, a little cleaner PHP:


<?php
    $myfield = get_post_meta($post->ID, 'short', true);

    /**
     * Checking if anything exists for the key short
     */
    if( $myfield ) {
        echo do_shortcode( $myfield );
    } else { 
        the_post_thumbnail();
    } 
?>

First of all, I must thank you for your response on my problem.

Yes, short is the name of the field. We can name it whatever we want. What I want is 2 codes

Code 1) If the “x” field is filled, display it to me. If it isn’t don’t show anything.

Code 2) If the “x” field is empty, show me the featured image. If it is filled then don’t show the featured image.

In code 1 I want it to show shortcodes , embed links of tweets, instagram photos, soundcloud etc..

1455 posts How's the surf doing?
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Had an item featured on Envato Market
  • Made it to the Authors' Hall of Fame
+6 more
tommusrhodus says

Short is the name of your meta field, but $short is a variable in your own code that is empty.

My changes in my comment above check for $myfield, which is what you should be checking, $short cannot be checked as nothing in your code is assigned to it.

65 posts
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
PurpleNinja says

Short is the name of your meta field, but $short is a variable in your own code that is empty. My changes in my comment above check for $myfield, which is what you should be checking, $short cannot be checked as nothing in your code is assigned to it.

I guess now I get the what was wrong in what I saw thinking. So I need

code 1) If there is a “short” field on the post, then it will show it to me. If there isn’t a” short” field then it shouldn’t do anything.

code 2) If there is a “short” field on the post, then it should not show me the featured image. If else there isn’t “short” field then it should show me the featured image.

1243 posts
  • Provided great contribution to our forums
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+6 more
Smartik says
$myfield = trim( get_post_meta($post->ID, 'short', true) );

//If `short` field exists and is set
if( !empty( $myfield ) ) {
        echo do_shortcode( $myfield );
} else { 
        the_post_thumbnail();
} 
65 posts
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
PurpleNinja says

$myfield = trim( get_post_meta($post->ID, 'short', true) );

//If `short` field exists and is set
if( !empty( $myfield ) ) {
        echo do_shortcode( $myfield );
} else { 
        the_post_thumbnail();
} 
What’s different is doing your Code?
65 posts
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
PurpleNinja says
code 1) If there is a “short” field on the post, then it will show it to me. If there isn’t a” short” field then it shouldn’t do anything. This code is ok
<?php
    $myfield = get_post_meta($post->ID, 'short', true);

    /**
     * Checking if anything exists for the key short
     */
    if( $myfield ) {
        echo do_shortcode( $myfield );
    } 
?>
code 2) If there is a “short” field on the post, then it should not show me the featured image or video. If else there isn’t “short” field then it should show me the featured image or video. I want help in this code…
<?php #featured video
                                if(!$disable_video) {                                    
                                    do_action('it_before_featured_video', it_get_setting('ad_video_before'), 'before-video');                                    
                                    if(!empty($video)) echo it_video($videoargs);                                     
                                    do_action('it_after_featured_video', it_get_setting('ad_video_after'), 'after-video');                                    
                                }                                
                                #featured image
                                if($thumbnail!='none' && has_post_thumbnail()) {                                 
                                    do_action('it_before_featured_image', it_get_setting('ad_image_before'), 'before-image');                                        
                                    echo it_featured_image($imageargs);                               
                                    do_action('it_after_featured_image', it_get_setting('ad_image_after'), 'after-image');                                    
                                } ?>
1243 posts
  • Provided great contribution to our forums
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
+6 more
Smartik says

Your problem is that you don’t know how PHP works. Your skills are limited and you ask for help on such simple questions.

I’m not going to help you anymore, because a good programer should find the solution itself. I will just explain 2 elements that you should consider in your code:

if( $var ) – will evaluate any value assigned to $var as true only if it is not equal with false, null or 0;
if( !empty( $var ) ) - will evaluate to true if $var is not empty, is not false or null, and if it exists

That’s it.

65 posts
  • Has collected 10+ items on Envato Market
  • Has been part of the Envato Community for over 3 years
PurpleNinja says

Your problem is that you don’t know how PHP works. Your skills are limited and you ask for help on such simple questions.

I’m not going to help you anymore, because a good programer should find the solution itself. I will just explain 2 elements that you should consider in your code:

if( $var ) – will evaluate any value assigned to $var as true only if it is not equal with false, null or 0;
if( !empty( $var ) ) - will evaluate to true if $var is not empty, is not false or null, and if it exists
That’s it.

Hello Smartik.

I don’t understand your attitude. I didn’t wrote anywhere that am a programmer or an expert in PHP. Instead of writing all of these stuff and being a smartass you could have written that SIMPLE solution and get over with it.

by
by
by
by
by
by