好吧,我设法弄明白了(经过太多的时间……):
这是代码,如果它很难看,请随时告诉我,因为我对wordpress和php都是新手:
//Query the wordpress database for product posts
$my_products = new WP_Query(
array(
\'post_type\' => \'product\',
)
);
//loop through my queried posts
<?php while ($my_products->have_posts()) : $my_products->the_post(); $_product = &new jigoshop_product( $post->ID );?>
//find the posts that have the meta_key \'featured\' with the value of \'yes\' (they all have a featured tag with either yes or no)
<?php if(get_post_meta($post->ID, \'featured\', yes) == \'yes\') : ?>
//make the product header a link to the product page
<h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1>
//copied this code for getting the product thumbs
<?php echo \'<div class="images">\';
$thumb_id = 0;
if (has_post_thumbnail()) :
$thumb_id = get_post_thumbnail_id();
// since there are now user settings for sizes, shouldn\'t need filters -JAP-
//$large_thumbnail_size = apply_filters(\'single_product_large_thumbnail_size\', \'shop_large\');
$large_thumbnail_size = jigoshop_get_image_size( \'shop_large\' );
//had to edit the href from original value to .get_permalink so it would link to product page instead of the image itself
echo \'<a href="\'.get_permalink().\'" rel="thumbnails">\';
the_post_thumbnail($large_thumbnail_size);
echo \'</a>\';
else :
echo jigoshop_get_image_placeholder( \'shop_large\' );
endif;
//commented out this section so it wouldn\'t thumbnail ALL the products images, just one
//do_action(\'jigoshop_product_thumbnails\');
echo \'</div>\'; ?>
//get the product description
<p><?php the_content(); ?></p>
//create the \'add to cart\' button
<a href="<?php echo $_product->add_to_cart_url(); ?>" class="button"><?php _e(\'Add to cart\', \'jigoshop\'); ?></a>
//reset the query (no idea if this is necessary, anyone?
<?php wp_reset_query(); ?>
<?php endif; ?>
<?php endwhile; ?>