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

Super simple PHP query WordPress

  • SOLVED

I'm gradually learning the basics of PHP, and have managed to patch together some code to go through several WP categories, outputting the category names of each and the 5 most recent posts, and output all the details.

I'm also trying to run the post_thumbnail through an image cropping script. All of this works well, but my lack of PHP knowledge means that although I can echo the post thumbnail url, I can't feed that URL into this bit of the PHP:

$ce_image->make( 'http://mysite.com/the/thumb/url/needs/to/go/here.jpg' );

It should be pretty simple to understand, but here's where I'm successfully outputting the URL now:

echo $src[0];

I just need to get that $src[0]; into the $ce_image bit!

Here's the full code:

<?php $cats = get_categories('exclude=1,330,331,332,333');
foreach ($cats as $cat) :
if(get_categories('child_of='.$cat->term_id)) continue;
$args = array(
'posts_per_page' =>5, // max number of post per category
'cat' => $cat->term_id
);
query_posts($args);

if (have_posts()) :

echo '<article class="listing idea-database group">';
echo '<h1 class="entry-title"><a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '" ' . '>';
echo '<span class="icon ' . $cat->slug . '"></span>';
echo $cat->name.'</a></h1>';
echo '<ul>';

while (have_posts()) : the_post();

//These 2 lines are outputting the URL of the thumbnail image correctly, but I actually need to pass this variable into the code block below
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumb-size');
echo $src[0];


?>

<li>
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><img src="
<?php

//Here's where the thumb URL needs to go - this next line crops the thumbnail to 150px by 150px, so the URL needs to be fed in so it can run the croppig process
$ce_image->make( 'http://mysite.com/the/thumb/url/needs/to/go/here.jpg' );


echo $ce_image->get_relative_path();
$ce_image->close();
?>" alt="<?php the_title(); ?> image" /><span class="idea-hover"><?php the_title(); ?></span></a>
</li>

<?php endwhile;
echo '</ul></article>';
endif;
wp_reset_query();

endforeach; ?>

Answers (1)

2011-05-25

Kailey Lampert answers:

Could you do this?

$ce_image->make( $src[0] );


Jon comments:

Perfect - guessing that's the easiest question you'll get to answer on here for a while ;)