Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Show thumbs or posts by author below a features post on homepage WordPress

I want to add a block to one of my custom pages which features an interview with one of my site contributors at the top (nice thumbnail, title, excerpt etc..) and below it 6 clickable thumbnails from posts they've added.

I have actually designed it all already, and it looks how I want it too, but the bit I can't figure out is make the 6 thumbnails at the bottom update each time the feature post updates (ie when I load a new interview, the thumbnails then change to reflect the posts by that new person). At the moment I would have to jump in and amend the user ID in the page template each time, which I would rather not.


If I could just add it to a custom field in the featured post that would be ideal, not really sure how to make that work though.

Thanks.




You can view the page here - http://dropdeadgorgeousdaily.com/test-page/

It's the fifth block down titles "on my list"


This is the code the I am using (it's probably not best practice, I did just patch it together)


<div class="HPcatblock_left" style="width: 275px; float: left; border-right: 1px solid rgb(239, 239, 239); padding-right: 20px; margin-left: 10px; padding-left: 5px;>


<?php $my_query = new WP_Query('category_name=reader-edit&showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID;?>
<a href="<?php the_permalink() ?>" rel="bookmark" title="SHOP IT <?php the_title_attribute(); ?>"><?php
if ( has_post_thumbnail() ) {
echo '<div class="post_wp_thumb" >';
the_post_thumbnail('single-post-thumbnail');
echo '</div>';
} else {
echo '<div class="post_wp_thumb">';
$image_link = get_first_image();
if ($image_link != "external"){
echo '<img src="/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $image_link .'&h=140&w=140&zc=1" alt="online fashion " height="140" width="140">';
} else {
echo '<img src="'. get_first_image_2() .'" height="100" alt="">';
}

echo '</div>';
}
?></a>
<p><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>" style="font-size: 14px;"><?php the_title(); ?></a>
</br><div style="overflow: hidden; line-height: 15px; height: 105px; font-size: 11px;"><?php the_excerpt(); ?></div></p>

<div id="sharebuttons" style="float: right; padding: 5px 35px 5px 5px; width: 120px; height: 20px; text-align: center; margin-top: 10px; ">
<div class="hpsharetop" style="width: 45px; height: 30px; float: left; display: block; padding-top: 3px; font-size:12px;">
<?php $shareUrl = urlencode(get_permalink($post->ID)); $shareTitle = urlencode($post->post_title); $fbLinkStats = @simplexml_load_file('http://api.facebook.com/restserver.php?method=links.getStats&urls='.$shareUrl); ?>
<a onclick='window.open("http://www.facebook.com/sharer.php?u=<?php echo $shareUrl; ?>&amp;t=<?php echo $shareTitle; ?>", "facebook", "toolbar=no, width=550, height=550"); return false;' href='http://www.facebook.com/sharer.php?u=<?php echo $shareUrl; ?>&amp;t=<?php echo $shareTitle; ?>' class='facebookShare'>

<?php if($fbLinkStats->link_stat->total_count == 0) { echo '0'; } elseif($fbLinkStats->link_stat->total_count == 1) { echo '1'; } else { echo $fbLinkStats->link_stat->total_count.''; } ?></a></div>

<div class="hpsharebott" style="width: 35px; height: 30px; float: left; display: block; padding-top: 3px; font-size:12px; ">

<a href="http://twitter.com/share?url=<?php echo urlencode(get_permalink(get_the_ID())); ?>&amp;title=<?php echo urlencode(get_the_title(get_the_ID())); ?>&amp;via=ddgdaily" target="_blank" class="tweetbutton"><?php echo tweetCount(get_permalink()); ?> </a></div>


<div style="width: 35px; height: 30px; float: left; display: block; margin-top:5px; font-size:12px; "> <a href="<?php the_permalink(); ?>#respond" class="commentsimg"><?php comments_number('0', '1', '% '); ?></a> </div>
</div>


<?php endwhile; ?>

</br>


<div style="width:270px; height:80px; margin:5px; padding:5px;">




<div class="just-added-comms-hp" style="float: left; border-top: 1px dotted rgb(239, 239, 239); padding-top: 10px; margin-top: 5px; width: 270px; margin-left: -8px;">

<?php $temp_query = $wp_query; ?>
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$sticky=get_option('sticky_posts');
$args=array(
'caller_get_posts'=>1,
'post_type' => 'dshop',
'author' => '8868',
'post__not_in' => $sticky,
'offset' =>1,
'paged'=>$paged,
'posts_per_page'=>6,
);
//query_posts($args);
$my_query = new WP_Query($args);

while ($my_query->have_posts()) : $my_query->the_post();
?>
<div class="swagshop_about" style="width:80px;margin-right: 5px; height: 80px; margin-bottom:10px;padding-right: 5px;">
<?php
if ( has_post_thumbnail() ) {
echo '<div class="post_wp_thumb" >';
the_post_thumbnail('single-post-thumbnail');
echo '</div>';
} else {
echo '<div class="post_wp_thumb_comm2" >';
$image_link = get_first_image();
$permalink = get_permalink($post->ID);
if ($image_link != "external"){
echo '<a href="'. $permalink .'"> <img src="/wp-content/themes/thesis_18/custom/scripts/timthumb.php?src='. $image_link .'&h=75&w=75&zc=1" alt="online fashion" title="online fashion"> </a>';
} else {
echo '<a href="'. $permalink .'"> <img src="'. get_first_image_2() .'" style="max-width:75px;" alt="online fashion" title="online fashion"> </a>';
}

echo '</div>';

}


?>

</div>

<div class="post-theme post" id="post-<?php the_ID(); ?>">
<div class="clear"></div>
</div>

<!-- Post -->
<?php endwhile; ?>
<br class="clear" />

<?php
$wp_query = $temp_query;
wp_reset_query();
?>


</div>

</div>

</div>



Answers (1)

2011-08-28

Christianto answers:

Hi,

I'm sorry if I misunderstood your question..

If the six thumbnail that appear are using author ID passing to the query, and the author ID is relative to author on previous query (in your code featured post with <em>category_name=reader-edit</em>), then you can save the author ID to a variable for example $author_ID and get the value from post object $post->post_author; inside your featured loop.
$author_ID = $post->post_author;

And then pass the $author_ID to as author ID to the 6 thumbnail argument.
$args=array(
'caller_get_posts'=>1,
'post_type' => 'dshop',
'author' => $author_ID,
'post__not_in' => $sticky,
'offset' =>1,
'paged'=>$paged,
'posts_per_page'=>6,
);


for complete code
http://pastebin.com/F10REiE3


kateM82 comments:

Hi there,

No they aren't the author of the featured posts, the admin will always be the author of that series of posts. So i think it will need to be a custom field of some sort.

Thanks


Christianto comments:

Ok,

if you use custom field to do it, use [[LINK href="http://codex.wordpress.org/Function_Reference/get_post_meta"]]get_post_meta[[/LINK]] function, change the $post->post_author; to get_post_meta($post->ID, 'thumbnail_author', true);

so it become..
$author_ID = get_post_meta($post->ID, 'thumbnail_author', true);

And the featured post create custom field named 'thumbnail_author' and put the ID as value, you can change whatever the name but it should match the name pass to get_post_meta function (case sensitive).

Hope this help