Support » Plugin: WP eCommerce » Add author and other datas to a WP E-Commerce product

Viewing 2 replies - 1 through 2 (of 2 total)
  • I succeeded in showing the related products by author thanks to the Custom taxonomies with Magic Fields 2 plugin.
    Then I used this code from Custom Related Posts using WordPress tags or taxonomies

    <?php // Related Products Taxonomy par illustrateur
    //for in the loop, display all "content", regardless of post_type,
    //that have the same custom taxonomy (e.g. genre) terms as the current post
    $backup = $post;  // backup the current object
    $found_none = '';
    $taxonomy = 'illustrateur';//  e.g. post_tag, category, custom taxonomy
    $param_type = 'illustrateur'; //  e.g. tag__in, category__in, but genre__in will NOT work
    $post_types = get_post_types( array('public' => true), 'names' );
    $tax_args=array('orderby' => 'none');
    $tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);
    if ($tags) {
      foreach ($tags as $tag) {
        $args=array(
          "$param_type" => $tag->slug,
          'post__not_in' => array($post->ID),
          'post_type' => $post_types,
          'showposts'=>-1,
          'caller_get_posts'=>1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
    	?>
    	<div class="meme">Du même illustrateur</div>
    	<?php
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
             <div class="wpec-related-product product-<?php echo wpsc_the_product_id(); ?> <?php echo wpsc_category_class(); ?>">
    
                            <?php if(get_option('on_wpec_image') == 'on') : ?>
                                <div class="wpec-related-image" id="related-pro-<?php echo wpsc_the_product_id(); ?>">
                                        <a href="<?php echo wpsc_the_product_permalink(); ?>">
    
                                            <?php if(wpsc_the_product_thumbnail()) : ?>
                                                        <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(100, 100); ?>"/>
                                            <?php else: ?>
                                                        <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="100" height="100" />
                                            <?php endif; ?>
                                        </a>
                                </div><!--close imagecol-->
                            <?php endif; ?>
    
                                <h5 class="wpec-related-title">
                                        <?php if(get_option('hide_name_link') == 1) : ?>
                                                <?php echo wpsc_the_product_title(); ?>
                                        <?php else: ?>
                                                <a class="wpsc_product_title" href="<?php echo wpsc_the_product_permalink(); ?>"><?php echo wpsc_the_product_title(); ?></a>
                                        <?php endif; ?>
                                </h5>
    
                            <?php if(get_option('on_wpec_price') == 'on') : ?>
                                <div class="product-info">
                                        <div class="pricedisplay <?php echo wpsc_the_product_id(); ?>"><?php _e('Price', 'wpsc'); ?>: <span id='product_price_<?php echo wpsc_the_product_id(); ?>' class="currentprice pricedisplay"><?php echo wpsc_the_product_price(); ?></span></div>
                                </div>
                            <?php endif; ?>
    
                        </div><!-- close default_product_display -->
    
            <?php $found_none = '';
          endwhile;
    	  ?>
    	   <div class="clear"></div>
    	 <?php
        }
      }
    }
    if ($found_none) {
    echo $found_none;
    }
    $post = $backup;  // copy it back
    wp_reset_query(); // to use the original query again
    ?>

    Hope it helps someone !

    Now I need to do the reverse thing, that is to say show all the books written by Author Y in the article regarding his biography.
    The article of an author is in the “blog” query, and I need to call the WP E commerce products query to make it work…
    Right now, here’s my result (it’s calling the same article, and giving the article a price of 0 €…) :
    http://ricochet-livres-jeunesse.fr/auteurs-illustrateurs/stephanie-heendrickxen/

    Any tips ?

    I found out how to create related products by author !
    I had to change some parts of my code above.

    1. First, create a custom taxonomy. I used Magic Fields 2 in order to create two taxonomies Auteur and Illustrateur, that I applied both to the Articles post types and the Product Pages post types.

    2. I went to my product articles and I picked the Auteur and Illustrateur of each articles.

    3. I went on my articles which are the biographies of the authors or illustrators of the products. I also checked the same taxonomy.

    4. Then I used this code from Custom Related Posts using WordPress tags or taxonomies while doing some modifications.

    First I deleted this line :

    $post_types = get_post_types( array('public' => true), 'names' );

    and

    changed

    'post_type' => '$post_types',

    into

    'post_type' => 'wpsc-product',

    so that the author article won’t appear in the list of related products.

    And here’s what I insert in my wpsc-single_product.php and single.php templates :

    <?php // Related Products Taxonomy par illustrateur
    //for in the loop, display all "content", regardless of post_type,
    //that have the same custom taxonomy (e.g. genre) terms as the current post
    $backup = $post;  // backup the current object
    $found_none = '';
    $taxonomy = 'illustrateur';//  e.g. post_tag, category, custom taxonomy
    $param_type = 'illustrateur'; //  e.g. tag__in, category__in, but genre__in will NOT work
    $tax_args=array('orderby' => 'none');
    $tags = wp_get_post_terms( $post->ID , $taxonomy, $tax_args);
    if ($tags) {
      foreach ($tags as $tag) {
        $args=array(
          "$param_type" => $tag->slug,
          'post__not_in' => array($post->ID),
          'post_type' => 'wpsc-product',
          'showposts'=>-1,
          'caller_get_posts'=>1
        );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
    	?>
    	<div class="meme">Du même illustrateur</div>
    	<?php
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
             <div class="wpec-related-product product-<?php echo wpsc_the_product_id(); ?> <?php echo wpsc_category_class(); ?>">
    
                            <?php if(get_option('on_wpec_image') == 'on') : ?>
                                <div class="wpec-related-image" id="related-pro-<?php echo wpsc_the_product_id(); ?>">
                                        <a href="<?php echo wpsc_the_product_permalink(); ?>">
    
                                            <?php if(wpsc_the_product_thumbnail()) : ?>
                                                        <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(100, 100); ?>"/>
                                            <?php else: ?>
                                                        <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="100" height="100" />
                                            <?php endif; ?>
                                        </a>
                                </div><!--close imagecol-->
                            <?php endif; ?>
    
                                <h5 class="wpec-related-title">
                                        <?php if(get_option('hide_name_link') == 1) : ?>
                                                <?php echo wpsc_the_product_title(); ?>
                                        <?php else: ?>
                                                <a class="wpsc_product_title" href="<?php echo wpsc_the_product_permalink(); ?>"><?php echo wpsc_the_product_title(); ?></a>
                                        <?php endif; ?>
                                </h5>
    
                            <?php if(get_option('on_wpec_price') == 'on') : ?>
                                <div class="product-info">
                                        <div class="pricedisplay <?php echo wpsc_the_product_id(); ?>"><?php _e('Price', 'wpsc'); ?>: <span id='product_price_<?php echo wpsc_the_product_id(); ?>' class="currentprice pricedisplay"><?php echo wpsc_the_product_price(); ?></span></div>
                                </div>
                            <?php endif; ?>
    
                        </div><!-- close default_product_display -->
    
            <?php $found_none = '';
          endwhile;
    	  ?>
    	   <div class="clear"></div>
    	 <?php
        }
      }
    }
    if ($found_none) {
    echo $found_none;
    }
    $post = $backup;  // copy it back
    wp_reset_query(); // to use the original query again
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Add author and other datas to a WP E-Commerce product’ is closed to new replies.