添加我自己的“添加到购物车按钮”

时间:2011-12-21 作者:Squadrons

我正在使用Jigoshop建立一个电子商务网站。

最终目标是在头版有一个特色产品部分。

Jigoshop提供了一个短代码,但该短代码默认为中等图像大小。我想使用较大的图像大小,因此我有条件地进行了WP\\U查询以检查特征图像,抓取了图像、产品标题和描述,但似乎不知道如何生成“添加到购物车”按钮。

有什么想法吗?

1 个回复
SO网友:Squadrons

好吧,我设法弄明白了(经过太多的时间……):

这是代码,如果它很难看,请随时告诉我,因为我对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; ?>         

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register