How can I split a Wordpress archive page into 2 columns?

what's the easiest way to have it not show the image/empty link?

Try replacing this:

Code:
<a href="<?php echo get_post_meta( $post->ID, 'website', true ); ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

with this:
Code:
<?php
$linkvar = get_post_meta( $post->ID, 'website', true );

if (isset($linkvar)) {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php } ?>

Just typed this up in a few seconds at work... so I might have overlooked something. I also might just be retarded. Let me know.
 


^^ That one didn't work. Even on the pages with no URL in the "website" custom field, it's still showing the image and linking to nothing. Thanks for working on it though. Any other variations that might do the trick?
 
Code:
<?php

$linkvar = get_post_meta( $post->ID, 'website', true );

if ($linkvar != "") {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php } ?>

That should work.



Breaking down the code:

1) Set variable linkvar to the value of the 'website' custom Wordpress field.
Code:
$linkvar = get_post_meta( $post->ID, 'website', true );

2) If variable linkvar isn't empty, show link.
Code:
if ($linkvar != "") {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php } ?>

3) Who needs an else?


ps. I wouldn't call that "working on it" .. just trying to save "Design, Development & Programming." but you're welcome ;)
 
Code:
<?php

$linkvar = get_post_meta( $post->ID, 'website', true );

if ($linkvar != "") {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php } ?>
That should work.



Breaking down the code:

1) Set variable linkvar to the value of the 'website' custom Wordpress field.
Code:
$linkvar = get_post_meta( $post->ID, 'website', true );
2) If variable linkvar isn't empty, show link.
Code:
if ($linkvar != "") {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php } ?>
3) Who needs an else?


ps. I wouldn't call that "working on it" .. just trying to save "Design, Development & Programming." but you're welcome ;)

Sweet. Worked like a charm. You're awesome.

For shits and giggles, instead of no image showing when no value was present, what if I wanted an alternate image to show instead, how would that work?

Let me also say that I'm not just begging for code here. I don't know much php at all, so I'm definitely learning from your examples every time you help, so I do appreciate it.
 
Code:
if ($linkvar != "") {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php }else{ ?>

Other image here

<?php } ?>
 
Well... remember step: 3) Who needs an else ?

The if{ } is what to do IF the website custom field has a value. In the original implimentation, because we don't want anything to display if it's empty, no ELSE is necessary.

With your new implimentation just add an ELSE{ }


NEW STEP 3) The Else Statement

Code:
<?php else{ ?>

<img src="/images/AlternateImage.png" />

<?php } ?>


All Together Now:

Code:
<?php

$linkvar = get_post_meta( $post->ID, 'website', true );

if ($linkvar != "") {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php }

 else{ ?>

<img src="/images/AlternateImage.png" />

<?php } ?>


Happy to help. I've been leeching valuable information off of this forum for years.
 
  • Like
Reactions: BlogHue
Well... remember step: 3) Who needs an else ?

The if{ } is what to do IF the website custom field has a value. In the original implimentation, because we don't want anything to display if it's empty, no ELSE is necessary.

With your new implimentation just add an ELSE{ }


NEW STEP 3) The Else Statement

Code:
<?php else{ ?>

<img src="/images/AlternateImage.png" />

<?php } ?>
All Together Now:

Code:
<?php

$linkvar = get_post_meta( $post->ID, 'website', true );

if ($linkvar != "") {
?>
    <a href="<?php echo $linkvar; ?>" target="_new"><img src="/images/visitthewebsite.png" alt="visit the website" /></a>

<?php }

 else{ ?>

<img src="/images/AlternateImage.png" />

<?php } ?>
Happy to help. I've been leeching valuable information off of this forum for years.

Cool thanks. I knew it was going to be an Else, and I almost had it working, but I didn't have it set up in it's own <?php } <?php } ?>
 
Question, in the last code example above, it obviously needs to start with

<?php

but that doesn't close before you started the new <?php } which closes at the end with <?php } ?>. Does the </a> close that initial <?php ?

How can it do that? I guess I'm just thinking in html where everything needs closing expression like <strong> </strong> to close the expression before you start another one.
 
It does close.

if ($linkvar != "") {
?> <--- here.

I had to close it, for the HTML... and then reopen it again when I'm ready for more PHP (closing the if statement).
 
It does close.

if ($linkvar != "") {
?> <--- here.

I had to close it, for the HTML... and then reopen it again when I'm ready for more PHP (closing the if statement).

Gotcha...didn't see that ?>

So why does the first one close with ?>, but the second one after the html closes with <?php } ?>?

I know this is a stupid question, but I'm just trying to plant this shit in my brain so I know the next time I'm working on it.
 
So why does the first one close with ?>, but the second one after the html closes with <?php } ?>?

<?php } ?> is actually a php open tag + a bracket that ends the else statement + a php close tag.

I had to close the php the first time, to insert the HTML it was going to output (the image). I then had to re-open the php, to add the } to close the if/else statements, after the HTML.


Open PHP tag:
Code:
[B]<?php[/B]

Close PHP tag:
Code:
[B]?>[/B]

Hope this helps.
 
Excellent. I'm upping my php iq as we speak.

Thanks the code is exactly what I needed too.
 
  • Like
Reactions: BlogHue