Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have been working on using featured image to create a list of items on the right column here:

http://www.julianamaeberger.com/soma/news/

The current featured image is now being given a class of "highlighted" so that you can tell which image is related to the post. I now need to move that li class="highlighted" to the top of the list so that it's always visible.

Is jquery sortable the best option here?

Thanks for any help in the right direction.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Can't you do this in HTML? So instead of printing everything in your loop, append it to a string that you print in the end. That way you can keep special stuff apart.

I assume this is a follow-up question to your previous question about featured images, so I will use the code from my answer there as an example.

<?php
$testimonials = get_posts( array(
    'category_name' => 'testimonial',
    'numberposts' => -1,
    'order' => 'DESC'
) );
$highlighted_testimonial_thumbnail = '';
$other_testimonial_thumbnails = '';
foreach ( $testimonials as $testimonial ) {
    if ( $testimonial->ID == $current_testimonial_id ) {
        $highlighted_testimonial_thumbnail = '<li class="highlighted">' . get_the_post_thumbnail( $testimonial->ID, 'nav' ) . '</li>';
    } else {
        $other_testimonial_thumbnails .= '<li>' . get_the_post_thumbnail( $testimonial->ID, 'nav' ) . '</li>';
    }
}
echo '<ul class="portfolio">';
echo $highlighted_testimonial_thumbnail;
echo $other_testimonial_thumbnails;
echo '</ul>';

Or more generic: instead of:

foreach ( $array_of_stuff as $stuff ) {
    echo $stuff
}

Do it like this:

$output = '';
$featured_output = '';
foreach ( $array_of_stuff as $stuff ) {
    if ( is_featured( $stuff ) ) {
        $featured_output = $stuff;
    } else {
        $output .= $stuff;
    }
}

echo $featured_output;
echo $output;

Almost all functions in WordPress that echo something have an equivalent that doesn't echo but just returns it. get_the_content() vs the_content() for example.

share|improve this answer
    
I had a feeling I was looking at this from the wrong angle. This worked perfected! –  juliana_mae Jan 2 '11 at 17:09
    
I did notice you added to your response - I had spent a day watching intro PHP tutorials to try to understand the first response, which turned out to be a good idea, in any case. This morning I saw that you edited your response and that was super helpful. I'm curious if you can recommend any resources on PHP and Wordpress development. I was maybe going to post this as an additional question, but I'm not sure if it's appropriate for this forum. It said it might be flagged as subjective. –  juliana_mae Jan 2 '11 at 17:17
    
@user1858: I could find at least two questions on this site about training material: one about books and one about generic material. I hope this helps you. And welcome to this site! I hope to see more good questions and answers from do. Do you have a username to use instead of the generic user1858? –  Jan Fabry Jan 2 '11 at 18:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.