I need some little help, if someone can help me I really appreciate I have this code: <?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>':'#'; ?> PHP: I want to display: '.get_post_meta(get_the_ID(),'post_external_link',true).' Code (markup): Or else: '.get_post_meta($post->ID, 'domaintag', true).' Code (markup): How I put in the code? I tried this but didn't worked: Can someone help me? Thanks!
What you have there is a short-form if / else already. First bit is the (get_post_meta(get_the_ID(),'post_external_link',true)) This is the if-statement, followed by a ? (question mark) for what is shown if that condition is true, namely here: '<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>' On the end, you have a : (colon) followed by a '#'; I'm not entirely sure what that # is there for, but if it's just some form of placeholder, you can add the code in your ELSE after that : (colon) (instead of the '#'
Hey buddy, thank you again for your help! Unfortunately my php knowledge is not so good... can you help me if I give you full code of the file? http://paste2.org/J2saOL6O Thanks
Btw, I tried this code: <?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); ?> PHP: first domaintag and second post_external_link... but didnt worked Only shows domaintag...
You need to copy all of it, including the <a> tag. Something like this: <?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, 'post_external_link', true).'</a>' : '<a href="'.g et_post_meta($post->ID, 'domaintag', true) .'>'.get_post_meta($post->ID, 'domaintag', true).'</a>'; PHP: Typed this on my phone, so there might be errors
Hey buddy, thank you for your reply and for trying to help me again. I tried that but didnt worked.... the code that I used: <?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>'; ?> PHP: Only the first <a> is working... after the : is not working... but if I switch 2nd <a> with the first, worked fine :/ Full code: http://paste2.org/ZAkb6GUj
I'm a little confused - first you check get_the_ID() with 'post_external_link' and true - if that check returns true (what comes directly after the question mark) you load the same (that you just checked) in the HREF of the a-tag, but for some reason you're using another get_post_meta as the link name - which I don't get. Wouldn't the smart thing be to use the same get_post_meta for both the HREF and the link name?
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 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>':'#'; ?> PHP: Appears like this: And with this code: <?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>':'#'; ?> PHP: Appears like this: 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) So I need href to be the same, but only "title" changes... Can you help me?
Aha. My bad, I misunderstood what you wanted. <?php echo $post_external_link = '<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.(get_post_meta(get_the_ID(),'post_external_link',true) ? get_post_meta(get_the_ID(),'post_external_link',true) : get_post_meta($post->ID, 'domaintag', true)).'</a>'; ?> PHP: This should in theory do what you want - I've moved the comparison / difference into only the visible link-part, instead of the whole code (the <a>-tag stays the same, only the visible link changes, as I understood you wanted it.
Thank you again for your help buddy, but unfortunately didnt worked ;( Sorry for waste your time with this... I added your code and the url that appeared was the given by get_post_meta(get_the_ID(),'post_external_link',true): and in this one should appeared other one because I have custom field in there: Any more ideas?
Hm - I'm thinking that it will ALWAYS equate to true about the post_external_link - ie, that will always be what triggers, it will never get to the else-part, even if you use that custom tag. Try switching the two checks around - ie, check to see if the domaintag-one is present, and if it is, show that - if not, show the post_external_link. Basically, change the check (the content within the first ()) and switch the two results with eachother.
Hey buddy, thank you once again!! My php knowledge is very poor... so I didnt understood too well what you tried to say... Will give you lots of work to write that code for me? Thank you once again!
Try this one: <?php echo $post_external_link = '<a href="'.get_post_meta(get_the_ID(),'post_external_link',true).'" '.$nofollow_tag.'>'.(get_post_meta($post->ID,'domaintag',true) ? get_post_meta($post->ID, 'domaintag', true) _ get_post_meta(get_the_ID(),'post_external_link',true)).'</a>'; ?> PHP: Granted, this assumes that the check for domaintag is correct
Yeahhhhh is finally working !!! Thank you bro !!! When I added the code appeared an error, after checking the code I notice this: ? get_post_meta($post->ID, 'domaintag', true) _ get_post_meta(get_the_ID(),'post_external_link',true)). PHP: I replaced the "_" with the ":" and worked Thanks to you!! Thank you once again!!!
Ops - sorry about that Probably went a little fast, and I missed the correct button. Glad you got it working.