Marketpress mp_productlist loop customization?

I want to customize how the products will display on multiple product pages to show the image first, then thumbnails of attached images (these are product variations) and then list the title and the price. (Screenshot of what I am trying to achieve attached)

I've studied the functions files for framemarket, gridmarket, and marketpress template functions and can't seem to figure out how to do this in a traditional style loop for my page template.

It does not have to be exact like my screenshot, but currently with the products that have multiple variations, marketpress does not show a price - just a choose options button.

Can someone kind of point me in the right direction? I want to make a basic page template (mp_productlist.php?) that will work for whatever the query is (tags, category, etc.) and I am thinking it should be simple format like this below (and not using technical code here!):

start loop - if have posts, get the posts - in the functions files there is a lot of queries going on, so I am most confused with this part. Would it suffice to copy something from a typical archives page in WP and adjust for custom post type? Any examples here would be so helpful!

mp_product_image or wordpress featured image fine too (got this!)

optional: mp_product attachments or php the excerpt or get custom fields (Not worried about the technical code for this and not a priority - just want to easily be able to add it in later)
php the title (got it!)
php mp_show price? - not sure if there is a function reference to hook into?
php end loop - will depend on how loop is started

Thanks for any ideas/advice/resources for helping me figure this out, I really appreciate it!

  • DavidM

    Hi chelle,

    That's a technical one I haven't really delved into myself, so I'm not sure how much help I might be on this but if you take a look on line 292 of template-functions.php you'll see this:

    foreach ($cart as $product_id => $variations) {
    foreach ($variations as $variation => $data) {
    $totals[] = $data['price'] * $data['quantity'];

    Besides getting the product price, you can get all the other needed data from that array. That section of code is getting the data from the cart but looking at it, I think you can just get the data directly using $product_id => $variations.

    Perhaps you could give that a try to start with?

    Cheers,
    David

  • chelle

    Thanks David! I am not very good at php function writing unfortunately do not really sure how to use that.

    Here is example code I am working with:

    <?php if ( class_exists( 'MarketPress' ) ) {
    ?>
    <?php
    query_posts(array('post_type' => 'product', 'paged' => $paged, 'posts_per_page'=>12));
    if (have_posts()) while (have_posts()) : the_post(); ?>

    <?php the_title(); ?>
    <?php mp_product_image(true, 'single', null); ?>
    <?php the_excerpt(); ?>
    <?php the_content(); ?>

    <?php endwhile; ?>
    <div class="clear"></div>
    </div>
    <?php
    }
    ?>

    This is a very basic loop for wordpress custom post type "product". Here is what I don't know:

    A. What is if class exists Marketpress? (Copied from gridmarket theme templates?)
    B. mp_product_image - what is "true, single, null"? Using this pulls the image for the single product page, I need it to pull the smaller one?
    C. This doesn't seem to work for tags or category pages - are those separate page templates or is there something I else I need to add to the query?
    D. How to add the price somewhere in here I don't nec. need an "add to cart" button, I can just do a link to the post.

    Anyways, as I don't know a whole lot, this my best guess - if anyone has any suggestions/ideas/good resources to read up on I would definitely appreciate it!

  • chelle

    Well, this is not resolved but I did figure out a temporary workaround. I installed the "Just Custom Fields" plugin and added my own custom field for what price to display. Seems silly to have to input a product price twice.

    This will display the price on a product without variations:

    <?php echo mp_product_price(false, $post->ID, ''); ?>

    but there really ought to be a way to display a price regardless of whether it has variations.

    I would think something like this should work, but I don't have the right meta key value:

    <?php echo get_post_meta($post->ID, 'mp_price', true) ?>

    I've tried a few different variations (price, mp_product_price, etc.), some display nothing, some display the word "Array". If anyone knows the right meta key to display the price let me know

    Anyways, I'm content to use the custom fields, but I am still not sure what the best method is for the actual post query so that it will show posts based on category/tag. Any suggestions for that?

  • chelle

    Still stuck on getting posts to properly query, so am pasting my pastebins here.

    This function seems to have the right querying for products based on tag/category (renamed simplemarket as to not interfere with any framemarket/marketpress functions) - I am not calling this function however as it does not have the formatting I want for the posts to display - I need to use custom fields, rearrange the title and the image, and wanted 3 items across instead of 4 and I really did not know how to do that in the functions file of the theme or the plugin file. But it does have the query part!

    http://pastebin.com/sY318Qi2

    This is the template I want to use to display the loop, with all the custom fields/div classes/thumbnails/etc. etc.

    http://pastebin.com/kSS65bYq

    Right now I have the template in mp_productlist.php but it does not sort by category or tag, so somehow I need to figure out how to marry these two files together so that if someone clicks on "red" only the items tagged red will show - right now because the query is too generic it shows all products no matter what category/tag. I tried creating an archives template for the custom post type, but that did not seem to work. Not sure if maybe I have this posted in the wrong place or if I need a more advanced query at the top to match the marketpress list products function example.

    I am so close to having it perfect, just getting stuck on this one little thing! Thanks for the help!

  • chelle

    Still struggling on this for querying the categories & tags dynamically with just 1 page template.

    So, my crappy workaround for now is to create a custom category page for each category (in this example mp_category-earrings.php) -- it's the only thing that actually pulls the right posts.

    Here's my example (pasted in template file mp_category-earrings.php) :

    <?php
     query_posts(array('post_type' => 'product', 'product_category'      => 'earrings', 'paged' => $paged, 'posts_per_page'=>12));
                        if (have_posts()) while (have_posts()) : the_post(); ?>

    I would really love if anyone can suggest any alternatives to display products by category or tags dynamically with just one template file! To do this for every single category and tag page is not ideal. I've searched everywhere, posted in wordpress.org forums and here...still no answer

  • Mason

    Just checking if it was eventually resolved in another thread? Or by yourself separately to us? Or by us over email with you? Or using our live support?

    If so, no need to reply, that's great news.

    If not, could you let us know by re-opening this topic, and we'll get onto it and helping you out asap!
    Otherwise, happy days, glad you got it sorted

    Thanks!

    p.s. I've also tagged Aaron here in case you do reopen this, as they'll definitely be able to help you!