go41

Re: Using default image if there is none assigned :: Reply by master

von Joern am 5. Apr. 2010 | Keine Kommentare

your featured section looks like this now in index.php

Code:

<?php while (have_posts()) : the_post(); ?>
   <div class="clearfloat">
   <?php $values = get_post_custom_values("Image");
   if (isset($values[0])) { ?>
      <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
   <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php
$values = get_post_custom_values("Image"); echo $values[0]; ?>&w=100&h=65&zc=1&q=100"
alt="<?php the_title(); ?>" class="left" width="100px" height="65px"  /></a>
      <?php } ?>
   <div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?></a>
<div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?> | <?php if(function_exists('the_views')) { the_views(); } ?>]</div>   

</div>
       </div>

      <?php endwhile; ?>

this just displays nothing if no image is assigned.

By adding an ‚else‘ statement you can show a default image!
Replace the above code with this one:

Code:

<?php while (have_posts()) : the_post(); ?>
   <div class="clearfloat">
   <?php $values = get_post_custom_values("Image");
   if (isset($values[0])) { ?>
      <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">
   <img src="<?php echo bloginfo('template_url'); ?>/scripts/timthumb.php?src=/<?php $values = get_post_custom_values("Image"); echo $values[0]; ?>&w=100&h=65&zc=1&q=100" alt="<?php the_title(); ?>" class="left" width="100px" height="65px"  /></a>
   <?php } else { // here comes the code for a default image in images folder called default100x65.jpg ?>
   <img src="<?php echo bloginfo('template_url'); ?>/images/default100x65.jpg" alt="<?php the_title(); ?>" class="left" width="100px" height="65px"  /></a>
   <?php } ?>
   <div class="info"><a href="<?php the_permalink() ?>" rel="bookmark" class="title"><?php the_title(); ?></a>
<div class="meta">[<?php the_time('j M Y') ?> | <?php comments_popup_link('No Comment', 'One Comment', '% Comments');?> | <?php if(function_exists('the_views')) { the_views(); } ?>]</div>   

</div>
       </div>

      <?php endwhile; ?>

and put your default image named default100x65.jpg in arthemias images folder.

Should work out of the box, right?
____________________
you find me on Google+, Twitter and Facebook

(von: master)

Hier noch 3 weitere Ergebnisse dieses Threads:

Using default image if there is none assigned

5. Apr. 2010 (von: qtest)

HiIn the Featured section, how can I use a default image if no image is provided. It would check for any image and use the one assigned. However if no image is assigned, only in the featured category, a default…

Re: Using default image if there is none assigned :: Reply by qtest

5. Apr. 2010 (von: qtest)

Worked seamlessly. ThanksHow can I ensure that proper CSS is applied to the image. Rite now, there is no border and padding?Sorry about my amateurishness. Weiterlesen →

Re: Using default image if there is none assigned :: Reply by master

5. Apr. 2010 (von: master)

Sorry, I forgot one line in the else part, the one giving the link, /a at the end is there already.Add this just after <?php } else { .........Code:<a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>">complete looks…

Autor:

Du findest mich auch auf Twitter und Facebook!

Schreibe einen Kommentar

Pflichtfelder sind mit * markiert.


Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.

weitere forum Beiträge: