Need some help with "else"

Status
Not open for further replies.

Divvy

Active Member
806
2009
18
0
I need some little help, if someone can help me I really appreciate :)

I have this code:
PHP:
<?php echo $post_external_link = (get_post_meta(get_the_ID(),'post_external_link',true))?'<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.get_post_meta(get_the_ID(),'post_external_link',true).'</a>':'#'; ?>

I want to display:
Code:
'.get_post_meta(get_the_ID(),'post_external_link',true).'

Or else:
Code:
'.get_post_meta($post->ID, 'domaintag', true).'

How I put in the code?
I tried this but didn't worked:
'.get_post_meta(get_the_ID(),'post_external_link',true).' } else { '.get_post_meta($post->ID, 'domaintag', true).'

Can someone help me? Thanks! :)
 
5 comments
PHP:
<?php echo $post_external_link = (get_post_meta(get_the_ID(),'post_external_link',true))?'<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.get_post_meta(get_the_ID(),'post_external_link',true).'</a>' : get_post_meta($post->ID, 'domaintag', true); ?>

Check here PHP Shorthand If / Else Examples
 
Hey buddy, thank you for your help!

Unfortunately the code didnt worked... can you help me if I give you full code of the file?
Paste2.org - Viewing Paste J2saOL6O

Thanks :)

__________________
Added after 5 minutes:

Btw, I tried this code:

PHP:
<?php echo $post_external_link = (get_post_meta(get_the_ID(),'post_external_link',true))?'<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.get_post_meta($post->ID, 'domaintag', true).'</a>' : get_post_meta(get_the_ID(),'post_external_link',true); ?>

first domaintag and second post_external_link... but didnt worked :(
Only shows domaintag...
 
Last edited:
Your code doesn't makes much sense, but I think this is mainly a syntax problem.

Try this:
Code:
<?php
    if (get_post_meta(get_the_ID(),'post_external_link',true)) {
        echo '<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>';
    } else if(get_post_meta($post->ID, 'domaintag', true)) {
        echo get_post_meta($post->ID, 'domaintag', true);
    }
?>
 
Hey buddy, thank you for your reply and for trying to help me :)


I tried that but didnt worked....

I also tried the following code:

PHP:
<?php echo $post_external_link = (get_post_meta(get_the_ID(),'post_external_link',true))?'<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.get_post_meta($post->ID, 'domaintag', true).'</a>':'<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.get_post_meta(get_the_ID(),'post_external_link',true).'</a>'; ?>


Only the first <a> is working... after the : is not working... but if I switch 2nd <a> with the first, worked fine :/
What could be?



Full code: Paste2.org - Viewing Paste ZAkb6GUj

__________________
Added after 5 Hours 38 minutes:

For a better understanding:

Ok, I'm going to explain better what I want to do, I think that is better for a better understanding :)


With this code:
PHP:
<?php echo $post_external_link = (get_post_meta(get_the_ID(),'post_external_link',true))?'<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.get_post_meta(get_the_ID(),'post_external_link',true).'</a>':'#'; ?>


Appears like this:
hCnEgn9.png



And with this code:

PHP:
<?php echo $post_external_link = (get_post_meta(get_the_ID(),'post_external_link',true))?'<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.get_post_meta($post->ID, 'domaintag', true).'</a>':'#'; ?>


Appears like this:
K94v8Qp.png



I want to show always the 1st code get_post_meta(get_the_ID(),'post_external_link',true)
But If custom field is added, I want to appear custom field first: get_post_meta($post->ID, 'domaintag', true)


VC8QfDO.png



Can you help me? :)
 
Last edited:
Status
Not open for further replies.
Back
Top