Hallo Leute,
bin Wordpress Neuling und absoluter PHP-Anfänger und ich hoffe, dass mir hier jemand helfen kann. Es geht um Folgendes: Es soll Artikel mit Bild und Artikel ohne Bild geben, d.h. wenn ich ein Bild hochlade, dann soll Variante A angezeigt werden und wenn ich kein Bild hochlade, dann Variante B.
Zum Hochladen des Bildes habe ich ein benutzerdefiniertes Feld 'Bild_klein' angelegt. Wenn ich nun in 'Bild_klein# ein Bild hochlade, dann soll folgende Variante genutzt werden:
<table width="550" height="232" border="0">
<tr>
<td width="300" height="238">
<img src="<?php echo $bild_klein; ?>" alt="<?php the_title(); ?>" /><br />
<span class="schriftklein">© <?php $fotocredit = get_post_meta($post->ID, 'Fotocredit', $single = true);
if($fotocredit !== '') echo $fotocredit;?></span>
</td>
<td width="20"> </td>
<td width="230" valign="bottom">
<div class="headline"><?php the_title(); ?></div><hr />
<hr>
<div class="subtitle"><?php $subtitle = get_post_meta($post->ID, 'subheadline', $single = true);
if($subtitle !== '') echo $subtitle;?></div><hr />
</td>
</tr>
</table>
Alles anzeigen
und wenn ich kein Bild hochlade, dann so
<div class="headline"><?php the_title(); ?></div><hr />
<hr>
<div class="subtitle"><?php $subtitle = get_post_meta($post->ID, 'subheadline', $single = true);
if($subtitle !== '') echo $subtitle;?></div><hr />
Hier der komplette Loop:
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<div id="datum"><?php the_time(__('j. F Y', 'kubrick')) ?> <!-- by <?php the_author() ?> --></div>
<?php $bild_klein = get_post_meta($post->ID, 'Bild_klein', $single = true);?>
<?php if(!empty($bild_klein)) ?>
<!-- Anfang Bereich ohne Bild: wenn kein Bild im benutzerdefinierten Feld 'Bild_klein', dann soll dieser Bereich hochgeladen werden -->
<div class="headline"><?php the_title(); ?></div><hr />
<hr>
<div class="subtitle"><?php $subtitle = get_post_meta($post->ID, 'subheadline', $single = true);
if($subtitle !== '') echo $subtitle;?></div><hr />
<!-- Ende Bereich ohne Bild -->
<?php else: ?>
<!-- Anfang Bereich mit Bild: wenn ein Bild in 'Bild_klein' hochgeladen wird, dann soll dieser Bereich hochgeladen werden -->
<table width="550" height="232" border="0">
<tr>
<td width="300" height="238">
<img src="<?php echo $bild_klein; ?>" alt="<?php the_title(); ?>" /><br />
<span class="schriftklein">© <?php $fotocredit = get_post_meta($post->ID, 'Fotocredit', $single = true);
if($fotocredit !== '') echo $fotocredit;?></span>
</td>
<td width="20"> </td>
<td width="230" valign="bottom">
<div class="headline"><?php the_title(); ?></div><hr />
<hr>
<div class="subtitle"><?php $subtitle = get_post_meta($post->ID, 'subheadline', $single = true);
if($subtitle !== '') echo $subtitle;?></div><hr />
</td>
</tr>
</table>
<!--Ende Bereich mit Bild -->
<?php endif; ?>
<!--der Bereich hier soll bei beiden Varianten angezeigt werden -->
<div class="entry">
<?php the_excerpt(__('Read the rest of this entry »', 'kubrick')); ?>
</div>
<div id="mehr"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'kubrick'), the_title_attribute('echo=0')); ?>" style="color:#4F0B0A;">mehr ...</a></div>
<div id="linie620schwarz"></div>
</div>
<?php endwhile; ?>
<div id="zurueck">
<div class="zurueck"><?php next_posts_link(__('» Ältere Artikel', 'kubrick')) ?></div>
<div class="zurueck"><?php previous_posts_link(__('» Neuere Artikel', 'kubrick')) ?></div>
</div>
<?php else : ?>
<h2 class="center"><?php _e('Not Found', 'kubrick'); ?></h2>
<p class="center"><?php _e('Sorry, but you are looking for something that isn’t here.', 'kubrick'); ?></p>
<?php get_search_form(); ?>
<?php endif; ?>
Alles anzeigen
Wär super, wenn ihr mir helfen könnt. Hab schon diverse Sachen probiert, hat aber leider alles nicht funktioniert. Die if-else-Geschichte hier im geposteten Loop z.B. auch nicht, gibt eine Fehlermeldung "syntax error, unexpected T_ELSE"
Freu mich auf euer Feedback.
KAtrin