• Resolved Haitham

    (@halkibsi)


    Hello,

    I have this condition statement working fine for me and outputting a list for based on custom fields

    <?php $recent = new WP_Query("cat=4&showposts=15"); while($recent->have_posts()) : $recent->the_post();?>
                                    <?php $image = get_post_meta($post->ID, 'imageThumb', true); ?>
                                    <?php $imageURL = get_post_custom_values("imageBig"); ?>
                                    <li><a href="<?php echo $imageURL[0]; ?>" rel="lightbox[image]" id="thumb<?php the_ID(); ?>"><img src="<?php echo $image; ?>" width="133" height="97" /></a></li>

    What I need is a condition statement to add the following to the “latest” item in that list<li id="mycarousel-item-1">

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Haitham

    (@halkibsi)

    Hi Michael!
    Thanks for your help. I searched Google but unfortunately I was using “WP if latest post condition” keywords, but yours are more relevant, thank you.

    I did find one this article which tackled what I wanted:
    https://jameswhittaker.com/journal/8-top-tips-for-wordpress-theme-development/

    but when I applied it, WP gives me a parse error. Here’s the code:

    <?php query_posts('cat=4&showposts=15&order=DESC'); ?>
    <?php $image = get_post_meta($post->ID, 'imageThumb', true); ?>
    <?php $imageURL = get_post_custom_values("imageBig"); ?>
    <?php $count = 1; ?>
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php if ($count == 1) : ?>
    <li id="mycarousel-item-1"><a href="<?php echo $imageURL[0]; ?>" rel="lightbox[image]" id="thumb<?php the_ID(); ?>"><img src="<?php echo $image; ?>" width="133" height="97" /></a></li>
    <?php else : ?>
    <li><a href="<?php echo $imageURL[0]; ?>" rel="lightbox[image]" id="thumb<?php the_ID(); ?>"><img src="<?php echo $image; ?>" width="133" height="97" /></a></li>
    <?php endif; $count++; ?>
    <?php endwhile; ?>

    any ideas? Thanks again.

    You’ve got two if statements and only one endif. Also I moved aroung the $image and $imageURL assignments to what seems a more appropriate location (inside your loop)

    Might try something like:

    <?php
    query_posts('cat=1&showposts=15&order=DESC');
    $count = 1;
    if (have_posts()) : while (have_posts()) : the_post();
    $image = get_post_meta($post->ID, 'imageThumb', true);
    $imageURL = get_post_custom_values("imageBig");
    if ($count == 1) { ?>
    <li id="mycarousel-item-1"><a href="<?php echo $imageURL[0]; ?>" rel="lightbox[image]" id="thumb<?php the_ID(); ?>"><img src="<?php echo $image; ?>" width="133" height="97" /></a></li>
    <?php  } else { ?>
    <li><a href="<?php echo $imageURL[0]; ?>" rel="lightbox[image]" id="thumb<?php the_ID(); ?>"><img src="<?php echo $image; ?>" width="133" height="97" /></a></li>
    <?php
    } // if ($count
    $count++;
    endwhile;
    endif;
    ?>

    Related:
    https://www.w3schools.com/php/php_if_else.asp

    Thread Starter Haitham

    (@halkibsi)

    Michael, thank you so much for your help.

    I’m a designer, not a coder. I am having a hard time digesting all of this code from so many references. But my life becomes less stressful because of generous people like you.

    Thank you again ??

    You are welcome. Good luck.

    Not related to WordPress, but I once had someone ask me to design a screen for him. I asked what he wanted the screen to look like…he held up a piece of blank lined paper and said, “can you make it look like this?”

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘if “latest post” condition’ is closed to new replies.