I'm using Version WP e-Commerce plugin

I used a custom post type "event" with multiple value field "event_photos" and the field type is wpsc-product.

To show a single "event" use single-event.php :

<?php while ( have_posts() ) : the_post(); ?>
                /* Include the single view for the event. 
                include TEMPLATEPATH.'/event-templates/single.php';

            <?php endwhile; // end of the loop. ?>

To show a list of products of a custom type "event" use "/event-templates/single.php" :

<div class="entry-show-products">
            <?php $event_photos_obj = get_field('event_photos'); //Show product in a list
                    if( $event_photos_obj ) :
                        echo '<ul>';
                        foreach ($event_photos_obj as $products) :
                                $target_product = get_field('event_picture_photo', $products->ID);
                                <div class="imagecol">
                                        if ( wpsc_the_product_thumbnail(0,0,$products->ID) ) : ?>
                                                <a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(
                                                ); ?>" href="<?php echo esc_url( wpsc_the_product_image(0,0,$products->ID) ); ?>">
                                                    <img class="product_image" id="product_image_<?php echo $products->ID ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(0,0,$products->ID); ?>"/>
                                    <?php endif; ?>
                                </div><!--close imagecol-->
                        <?php endforeach;
                        echo '</ul>';
                    else :                  
                        echo "Δεν υπάρχει φωτογραφία";
                    endif; ?>
        </div><!-- .entry-show-photo -->

My question is how to tell wp to index in a specific product and then using the template code "wpsc-single_product.php" :

    <div id="single_product_page_container">

        // Breadcrumbs

        // Plugin hook for adding things to the top of the products page, like the live search
        do_action( 'wpsc_top_of_products_page' );

    <div class="single_product_display group">
         * Start the product loop here.
         * This is single products view, so there should be only one

                    <div class="imagecol">
                        <?php if ( wpsc_the_product_thumbnail() ) : ?>
                                <a rel="<?php echo wpsc_the_product_title(); ?>" class="<?php echo wpsc_the_product_image_link_classes(); ?>" href="<?php echo esc_url( wpsc_the_product_image() ); ?>">
                                    <img class="product_image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="<?php echo wpsc_the_product_title(); ?>" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo wpsc_the_product_thumbnail(); ?>"/>
                                if ( function_exists( 'gold_shpcrt_display_gallery' ) )
                                    echo gold_shpcrt_display_gallery( wpsc_the_product_id() );
                        <?php else: ?>
                                    <a href="<?php echo esc_url( wpsc_the_product_permalink() ); ?>">
                                    <img class="no-image" id="product_image_<?php echo wpsc_the_product_id(); ?>" alt="No Image" title="<?php echo wpsc_the_product_title(); ?>" src="<?php echo WPSC_CORE_THEME_URL; ?>wpsc-images/noimage.png" width="<?php echo get_option('product_image_width'); ?>" height="<?php echo get_option('product_image_height'); ?>" />
                        <?php endif; ?>
                    </div><!--close imagecol-->

        </div><!--close single_product_display-->

        <?php echo wpsc_product_comments(); ?>

<?php do_action( 'wpsc_theme_footer' ); ?>

</div><!--close single_product_page_container-->

Is it better way to use WP_Query?

global $post;

  foreach ($event_photos_obj as $post) :

  // set up product in order to use native wordpress api

 /* Include the single view for the product (photo). */
 include  .....


my mistake my code is that setup_postdata with $product instead of $post as the tutorial said : https://codex.wordpress.org/Function_Reference/setup_postdata

This is one way, the second way uses WP_Query http://codex.wordpress.org/Class_Reference/WP_Query but in my case I don't need because I have already the object from the WP E-Commenrce with his functions and everything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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