Setting up a shop – how to structure, like posts or pages?
-
I want to set up a shop on my website, but wondering how to structure the products? Do I do each product as a post, or each product as their own page?
I sell books for photographers and there are about 30 books or so.
I’m not sure how to go about it, anyone with experience that would point me in the right direction?
-
Use posts if you want to categorize or tag those products.
Use Pages if you don’t need categories or tags.
Thanks for your reply.
Yes, i would like to categorize. So this is what i do?:
-Add Book 1 as a post with Paypal “add to basket button”, add Book 2 as a post with Paypal “add to basket button” and so on.
-After each post that is a news article, can i call up the book posts that relate to the same category somehow?Why don’t you look into the WP e-Commerce plugin?
@vtxyzzy
I did, but I could not get it to work!
How do you structure the product pages with it, if i can get it to work. I would like something that will show products relevant to the post (same category) at the end of the post.-After each post that is a news article, can i call up the book posts that relate to the same category somehow?
Use the Category Widget or template tag, wp_list_categories(), in your sidebar to present a list of categories that when clicked will take you to all the posts in that category.
I would like something that will show products relevant to the post (same category) at the end of the post.
A related post plugin will do that or this code:
Display posts belonging to the categories of the current post without duplicating the present post <?php global $post; $cat_ID=array(); $categories = get_the_category(); //get all categories for this post foreach($categories as $category) { array_push($cat_ID,$category->cat_ID); } $args = array( 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'numberposts' => 8, 'post__not_in' => array($post->ID), 'category__in' => $cat_ID ); // post__not_in will exclude the post we are displaying $cat_posts = get_posts($args); $out=''; foreach($cat_posts as $cat_post) { $out .= '<li>'; $out .= '<a href="'.get_permalink($cat_post->ID).'" title="'.wptexturize($cat_post->post_title).'">'.wptexturize($cat_post->post_title).'</a></li>'; } $out = '<ul class="cat_post">' . $out . '</ul>'; echo $out; ?>
Related:
Stepping Into Template Tags
Stepping Into Templates
Template HierarchyHere’s another ecommerce plugin and the author does a good job of ‘support’: https://www.ads-software.com/extend/plugins/eshop/
@michaelh
Thank you so much for your help. I will try this out. Just one more question, that will probably complicate things further. Can i somehow add “Related posts” only if they also are tagged as “Books” or “Products”?Didn’t test, but change the $args statement to something like:
$args = array( 'tag__in' => array(5,9), 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'numberposts' => 8, 'post__not_in' => array($post->ID), 'category__in' => $cat_ID );
Assumes that Books and Products are tag ID 5 and 9 respectively. See How do I determine a Post, Page, Category, Tag, Link, Link Category, or User ID?
@michaelh
Thank you for the added script. I added it to the “single.php” but it does not show up.
The test post for products is category Books (84) and Cyanotypes.
The test post for the post is category Cyanotypes.
Have i got the categories backwards or something?
Here is the whole script i’m using:<!--display books and magazines in the same categories of the current post--> The books and magazines should show up here. <?php global $post; $cat_ID=array(); $categories = get_the_category(); //get all categories for this post foreach($categories as $category) { array_push($cat_ID,$category->cat_ID); } $args = array( 'tag__in' => array(84,85), 'post_type' => 'post', 'numberposts' => 20, 'post__not_in' => array($post->ID), 'category__in' => $cat_ID ); // post__not_in will exclude the post we are displaying $cat_posts = get_posts($args); $out=''; foreach($cat_posts as $cat_post) { $out .= '<li>'; $out .= '<a href="'.get_permalink($cat_post->ID).'" title="'.wptexturize($cat_post->post_title).'">'.wptexturize($cat_post->post_title).'</a></li>'; } $out = '<ul class="cat_post">' . $out . '</ul>'; echo $out; ?>
It does show the line “The books and magazines should show up here.” so i think it’s in the right place.
Really appreciate your time and effort!@michaelh
Back again. I have perhaps an easier solution (if you could help me)
I have a related posts in the sidebar.
There is a small error with the script, and it’s that it only calls up posts from the first category of the post.
I would like the first section to call up posts from all categories of the post, apart from 85 and 85, which are books and magazines. Is that possible?
And, to solve the previous problem, add a similar one that says “Books and related reading” and add those separately?
Like this (but with the tweek on the categories, which i need help with if possible)<!--script call up posts of the same category starts--> <?php if ( is_single() ) { $cats = wp_get_post_categories($post->ID); if ($cats) { $first_cat = $cats[0]; $args=array( 'cat' => $first_cat, //cat__not_in wouldn't work 'post__not_in' => array($post->ID), 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo '<h3 class="widgettitle">Articles on the same subject</h3>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <p style="padding:0px 8px 0px 16px"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php endwhile; } //if ($my_query) } //if ($cats) wp_reset_query(); // Restore global post data stomped by the_post(). } //if (is_single()) ?> <!--script same category ends--> <!--script call up posts of the same category from books and magazines only--> <?php if ( is_single() ) { $cats = wp_get_post_categories($post->ID); if ($cats) { $first_cat = $cats[0]; $args=array( 'cat' => $first_cat, //cat__not_in wouldn't work 'post__not_in' => array($post->ID), 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { echo '<h3 class="widgettitle">Books and further reading</h3>'; while ($my_query->have_posts()) : $my_query->the_post(); ?> <p style="padding:0px 8px 0px 16px"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p> <?php endwhile; } //if ($my_query) } //if ($cats) wp_reset_query(); // Restore global post data stomped by the_post(). } //if (is_single()) ?> <!--script same category ends-->
From my notes, pick what you need out of it:
Display posts belonging to the categories of the current post without duplicating the present post <?php global $post; $cat_ID=array(); $categories = get_the_category(); //get all categories for this post foreach($categories as $category) { array_push($cat_ID,$category->cat_ID); } $args = array( 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'numberposts' => 8, 'post__not_in' => array($post->ID), 'category__in' => $cat_ID ); // post__not_in will exclude the post we are displaying $cat_posts = get_posts($args); $out=''; foreach($cat_posts as $cat_post) { $out .= '<li>'; $out .= '<a href="'.get_permalink($cat_post->ID).'" title="'.wptexturize($cat_post->post_title).'">'.wptexturize($cat_post->post_title).'</a></li>'; } $out = '<ul class="cat_post">' . $out . '</ul>'; echo $out; ?>
@michaelh
Thank you.
How do i get it to exclude cat 84,85 in the first section?
$categories = get_the_category(); //get all categories for this post except for 84 and 85
And for the second part, do i change it to just show category 84,85 like this?
$categories = get_the_category(84,85); //get just categories 84 and 85
foreach($categories as $category) { if ($category->cat_ID != 85 && $category->cat_ID != 86) { array_push($cat_ID,$category->cat_ID); } }
ok, please forgive me, i know not what i am doing.
i need help with my page. my husbands friend set up my site, and he didn’t know what he was doing. so i am selling baby headbands and stuff like that, and set up my wordpress page, with all it’s categories and all of my products. he then installed wp commerce plug in, and i don’t know what the heck to do. i have been sitting at the computer all day trying to figure this out.so i did all my categories again, and trying to put my products in these categories, but nothing is working. i see all the categories on my homepage, but then when i try to click on them, nothing is clicking. and also at the top of my page is a link to my products page. i want my customers to be able to click on a category on the sidebar, and get sent to that page and be able to peruse all the products that way. i am not understanding why customers will only be able to see products if they go to the product page. please help!!!!
i know nothing about setting up websites, so please no one rip me to shreds, i just really appreciate anyones help.never mind, figured it out!!
- The topic ‘Setting up a shop – how to structure, like posts or pages?’ is closed to new replies.