Forum Replies Created
-
AuthorPosts
-
FireSamuraiMember
Okay, thanks.
April 15, 2011 at 3:40 am in reply to: There's an extra space between variation name and colon. #31356FireSamuraiMemberI tried that earlier, and had removed all the spaces in all the locations, so it looked like this “: “, but it didn’t seem to work. I might have missed one though. I’ll try it again and report back.
Thanks.
April 15, 2011 at 12:02 am in reply to: Display products in category using fancy 1 and no thumbs #31312FireSamuraiMemberThanks for the help. I decided to go another route and create a custom shortcode so that I could get the functionality I needed for a custom product layout.
Explanation here.
As always, I appreciate your courtesy and help. Have a great day!
FireSamuraiMemberOne area that seems to work, but I’m not sure if I did it right, is in the categories shortcode,
if(strpos($url,'product_page=')) // Removed ? from '?product_page='. We want to first check if the string 'product_page=' exists, and then add '?' to it instead of checking for '?product_page=' and then adding another '?' to it.
I removed a ? from before product_page=. My reasoning is explained in the commented out text… is that reasoning correct?
Also in the category code above, 8 lines up from the end, there is a section that looks like this:
$output .= '
';
There are two line breaks in that, but the forum interprets them as actual line breaks. It should look like this:
$output .= '<br /><br />';
Hope that helps.
FS
FireSamuraiMemberOkay, here it is. This is actually a custom shortcode that provides all the stuff I needed for a particular item type.
[product id=1 type=1]
: Display Product ID 1 with Add to Cart button[product id=1 type=2]
: Display Product ID 1 with Buy Now button[product id=1 type=3]
: Display Product ID 1 with Subscribe button[product id=1 type=4]
: Display Product ID 1 with Download buttonIt looks for the following (listed in no particular order):
* A generic image
* Product ID
* Product description
* Sale price
* Regular price
* Button type
* Quantity available
* Quantity field
CSS shown after the shortcode’s code.
/*
* DISPLAY INDIVIDUAL PRODUCTS WITH CUSTOM LAYOUT
*
* @author Chris Mower (borrowing heavily on the core functionality and hard work done by Tips & Tricks HQ)
* @link http://www.chrismower.com
* @link http://www.tipsandtricks-hq.com
*/
// Adds the shortcode
add_shortcode('product', 'cm_display_product');
function cm_display_product($atts){
extract(shortcode_atts(array(
'id' => 'no id',
'type' => '1',
), $atts));
return cm_display_product_guts($id,$type);
}
// Functionality behind the shortcode
function cm_display_product_guts($id,$button_type=1) {
global $wpdb;
$products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
$ret_product = $wpdb->get_row("SELECT * FROM $products_table_name WHERE id = '$id'", OBJECT);
$imageName = 'image.png';
$imagePath = '<img src="YOUR IMAGE URL HERE/'.$imageName.'" />'; // Add universal image here
$output = '<div class="product-box">';
// Display a generic image
$output .= '<div class="product-img">'.$imagePath.'</div><!-- end .product-img -->';
$output .= '<div class="product">';
// Show product name with link to product URL
$output .= '<div class="product-name">product_url.'">'.$ret_product->name.'</div>';
// Display product description if field is populated
if(!empty($ret_product->description)){
$output .= '<div class="product-description">'.html_entity_decode($ret_product->description, ENT_COMPAT,"UTF-8").'</div><!-- end .product-description -->';
}
// Display available copies if field is populated
if (!empty($ret_product->available_copies))
$output .= '<div class="product-qty"><span id="qty-text">'.ESTORE_AVAILABLE_QTY.': </span>'.$ret_product->available_copies.'</div><!-- end .product-qty -->';
$output .= '<div class="prices-container">';
// Display original (old) price if field is populated
if(!empty($ret_product->old_price)){
$output .= '<div class="product-old-price"><span id="old-price-text">'.ESTORE_OLD_PRICE.': </span>'.WP_ESTORE_CURRENCY_SYMBOL.$ret_product->old_price.'</div><!-- end .product-old-price -->';
}
// Display product price if field is not equal to 0
if($ret_product->price != 0) {
$output .= '<div class="product-price"><span id="price-text">'.ESTORE_PRICE.': </span>'.print_digi_cart_payment_currency($ret_product->price, WP_ESTORE_CURRENCY_SYMBOL, ".").'</div><!-- end .product-price -->';
}
$output .= '</div><!-- end .prices-container -->';
// Display different button types
$output .= '<div class="product-button">';
if($button_type == 1)
{
// Add to Cart
$output .= get_button_code_for_element($ret_product, false);
}
else if ($button_type == 2)
{
// Buy Now
$output .= print_eStore_buy_now_button($id);
}
else if ($button_type == 3)
{
// Subscribe
$output .= print_eStore_subscribe_button_form($id);
}
else if ($button_type == 4)
{
// Download
$output .= eStore_show_download_now_button($id);
}
$output .= '</div><!-- end .product-button -->';
$output .= '</div><!-- end .product -->';
$output .= '</div><!-- end .product-box -->';
return $output;
}
Here is the CSS I used to style it:
/* Individual Product Styles */
.product-box {
border-bottom-color:#cccccc9; /* IE8 and below */
border-bottom-style:dashed9; /* IE8 and below */
border-bottom-width:1px9; /* IE8 and below */
-moz-box-shadow:0 0 3px 1px rgba(3, 101, 191, 1);
-khtml-box-shadow:0 0 3px 1px rgba(3, 101, 191, 1);
-webkit-box-shadow:0 0 3px 1px rgba(3, 101, 191, 1);
box-shadow:0 0 3px 1px rgba(3, 101, 191, 1);
font-size:14px;
margin:20px 0 0;
padding:0;
overflow:hidden;
}
.product-img {
border:none;
float:left;
height:50px;
width:50px;
margin:10px;
padding:0;
}
.product {
padding:10px 10px 10px 75px;
margin:0;
}
.product-name {
background:none;
border-bottom:1px dotted #bbbbbb;
font-size:16px;
font-weight:500;
margin:0 0 5px;
padding:0 0 5px 0;
}
.product-description {
margin:2px 0;
}
.product-qty {
font-style:italic;
float:right;
}
#qty-text { }
.prices-container {
font-weight:bold;
margin:2px 0;
overflow:hidden;
}
.product-price {
float:left;
font-size:14px;
margin:2px 0;
}
#price-text { }
.product-old-price {
color:red;
float:left;
font-style:italic;
margin:2px 10px 2px 0;
padding:0;
text-decoration:line-through;
}
#old-price-text { }
.product-button {
margin:0 0 10px;
padding:0;
}
.product-box .eStore-button-form { }
.product-box .eStore_variation { /* variation drop-down */
margin:0 20px 3px 2px;
}
.product-box .eStore-button-form input[type="text"] { /* quantity box */
margin:3px 15px 3px 2px;
}
.product-box input.eStore_button { /* Add to Cart, etc. button */
margin:3px 0 10px 2px;
float:right;
}
But… after all that was said and done, I realized I needed a category shortcode to also display that same style… so to do that I created another shortcode for categories. So, here it is…
[pcat id=2 type=1 order=1]
: Displays all products in category 2, uses Add to Cart button, orders by product ID ascending[pcat id=2 type=1 order=1 number=4]
: Displays all products in category 2, uses Add to Cart button, orders by product ID ascending, limits products per page to 4Keep in mind that the usual button types and order structures provided by Tips & Tricks HQ works within this shortcode. The first shortcode example doesn’t use the number parameter. You can leave it out and it will default to whatever the products-per-page setting is in the Admin Panel’s General Settings.
Here’s the code (CSS shown after).
/*
* DISPLAY CATEGORIES WITH CUSTOM LAYOUT
*
* @author Chris Mower (borrowing heavily on the core functionality and hard work done by Tips & Tricks HQ)
* @link http://www.chrismower.com
* @link http://www.tipsandtricks-hq.com
*/
//Adds the shortcode
add_shortcode('pcat', 'cm_display_category');
function cm_display_category($atts){
extract(shortcode_atts(array(
'id' => 'no id', // defaults to no category ID specified
'order' => '1', // defaults to order by product ID ascending
'type' => '1', // defaults to 'add to cart'
'number' => '0', // defaults to products-per-page setting
), $atts));
return cm_display_category_guts($id,$order,$type,$number);
}
// Functionality behind the shortcode
function cm_display_category_guts($id,$order=1,$button_type=1,$number=0)
{
// Checks id attribute to see if it's set in the shortcode
if($id == 'no id')
{
return '<div class="cat-no-id-text">Oops! You did not specify a category ID. Please enter a category ID with this shortcode.</div><!-- end .cat-no-id-text -->';
}
// Checks to see if number is specified in shortcode, if not specified, adds pagination with these rules
if($number == 0)
{
$i = 0;
// Set pages to include $limit records per page
$limit = get_option('eStore_products_per_page');
// If the products-per-page setting is empty, use this limit
if(empty($limit))
{
$limit = 9999; // Set new limit here
}
// If products-per-page setting is populated, create product pages
if (isset($_GET))
{
$page = $_GET;
}
// If no product pages are set stay on page 1
else
{
$page = 1;
}
$start = ($page - 1) * $limit;
}
// If shortcode specifies a number, limit entries to that number
else{
$start = 0;
$limit = $number;
}
global $wpdb;
$cat_prod_rel_table_name = $wpdb->prefix . "wp_eStore_cat_prod_rel_tbl";
$products_table_name = WP_ESTORE_PRODUCTS_TABLE_NAME;
// Sort by product ID ascending
if($order == 1)
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name where cat_id=$id LIMIT $start, $limit", OBJECT);
}
// Sort by product ID descending
else if($order == 2)
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name where cat_id=$id ORDER BY prod_id DESC LIMIT $start, $limit", OBJECT);
}
// Sort by product name ascending
else if($order == 3)
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name INNER JOIN $products_table_name ON $cat_prod_rel_table_name.prod_id=$products_table_name.id where cat_id=$id ORDER BY name LIMIT $start, $limit", OBJECT);
}
// Sort by product name descending
else if($order == 4)
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name INNER JOIN $products_table_name ON $cat_prod_rel_table_name.prod_id=$products_table_name.id where cat_id=$id ORDER BY name DESC LIMIT $start, $limit", OBJECT);
}
// Sort by available copies ascending
else if($order == 5)
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name INNER JOIN $products_table_name ON $cat_prod_rel_table_name.prod_id=$products_table_name.id where cat_id=$id ORDER BY available_copies LIMIT $start, $limit", OBJECT);
}
// Sort by available copies descending
else if($order == 6)
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name INNER JOIN $products_table_name ON $cat_prod_rel_table_name.prod_id=$products_table_name.id where cat_id=$id ORDER BY available_copies DESC LIMIT $start, $limit", OBJECT);
}
// Sort by price ascending
else if($order == 7)
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name INNER JOIN $products_table_name ON $cat_prod_rel_table_name.prod_id=$products_table_name.id where cat_id=$id ORDER BY price LIMIT $start, $limit", OBJECT);
}
// Sort by price descending
else if($order ==
{
$wp_eStore_db = $wpdb->get_results("SELECT * FROM $cat_prod_rel_table_name INNER JOIN $products_table_name ON $cat_prod_rel_table_name.prod_id=$products_table_name.id where cat_id=$id ORDER BY price DESC LIMIT $start, $limit", OBJECT);
}
$totalrows = $wpdb->get_var("SELECT COUNT(*) FROM $cat_prod_rel_table_name where cat_id=$id;");
// Display products using custom layout
if ($wp_eStore_db)
{
foreach ($wp_eStore_db as $wp_eStore_db)
{
$output .= cm_display_product_guts($wp_eStore_db->prod_id,$button_type);
}
}
else
{
$output .= '<div class="cat-no-products-text">There are no products to display in this category</div><!-- end .cat-no-products-text -->';
}
//Clear the float
$output .= '<div class="eStore-fancy-clear"></div><!-- end .eStore-fancy-clear -->';
// Checks to see if there are more database entries than to what the limit is set
if ($totalrows > $limit && $number == 0)
{
// Determines how many pages to display
$pages = ceil($totalrows / $limit)+1;
$separator = '?'; // Default permalink & product page separator
$url = get_permalink();
$pagesText = 'Product Pages: ';
// Sets appropriate URL separator depending on what's found in the permalink
if(strpos($url,'product_page=')) // Removed ? from '?product_page='. We want to first check if the string 'product_page=' exists, and then add '?' to it instead of checking for '?product_page=' and then adding another '?' to it.
{
$separator = '?';
}
else if(strpos($url,'?') !== false)
{
$separator = '&'; // Creates proper URL string
}
$output .= '<div class="cat-page-tabs-container">';
$output .= '<div id="cat-pages-text">'.$pagesText.'</div>';
for($r = 1;$r<$pages;$r++) // Starts pagination at 1 and loops
{
$output .= '<div id="cat-page-tabs">'.$r.'</div><!-- end #cat-page-tabs -->';
// Once the remainder of pages reaches zero, ouput some breaks
if ($r%15 == 0)
{
$output .= '
';
}
}
$output .= '</div><!-- end .cat-page-tabs-container -->';
}
return $output;
}
And of course, that needs to be styled, so here is the CSS I used.
/* List Product Category Styles with Custom Product Structure */
.cat-no-id-text, .cat-no-products-text {
color:#000000;
font-style:italic;
}
.cat-page-tabs-container {
background:transparent;
margin:5px 0 15px;
padding:5px;
overflow:hidden;
clear:both;
}
#cat-pages-text {
float:left;
margin:2px 0 0;
}
#cat-page-tabs {
background:#f0f0f0;
border:1px solid #000000;
margin:0 0 0 5px;
padding:1px 7px 2px;
float:left;
}
Well, for whoever comes across this, hope it helps.
Cheers!
FS
FireSamuraiMemberI had a 1:00 a.m. epiphany of how to do this, so I hopped out of bed and pounded out a sweet lil’ shortcode. I’ll post my solution tomorrow once I’ve got it all styled up nice.
Peace, and good night!
FireSamuraiMemberWould it be easier to remove the thumb from
[wp_eStore_fancy1_no_price id=#]
or to remove the price from
[wp_eStore_fancy1_no_thumbnail id=#]
?or to combine the two into a new shortcode?
Thanks again,
FS
FireSamuraiMemberSweet! That did the trick, thank you! To make it display to the right of the Quantity [X] field, I added it above the block of code you mentioned and tweaked it a little bit by giving it it’s own class.
$output .= '<div class="eStore-fancy5-quantity">(Only '.$ret_product->available_copies.' available)</div>';
Then I added that class to my css.
.eStore-fancy5-quantity {float:right; margin:8px 25px 0 0; font-weight:bold;}
Thanks again, I appreciate your help.
-
AuthorPosts