Tips and Tricks HQ Support Portal › Forums › WP eStore Forum › How to display limited number of products within category
Tagged: Tweaks
- This topic has 6 replies, 2 voices, and was last updated 13 years, 11 months ago by amin007.
-
AuthorPosts
-
December 9, 2010 at 9:50 pm #2352MaryMember
Hello,
I’m getting really close to completing my store’s conversion to WP eStore and things are looking good!
But, I have one problem I can’t seem to figure out. I need to show a limited number of products from a certain category. Here’s what I’m trying to do: I have a page where I’m showing a category of products that has several subcategories. I want to be able to show 3 products from each of the main and subcategories, each with a ‘More’ button that the customer can click to see additional products from each category. I’m thinking I need something like: [wp_eStore_category_products_fancy number=3 id=1 style=3 order=3], but the ‘number’ modifier isn’t part of the original function and I don’t know if and how it can be altered to include it.
Does anyone have any ideas?
Thanks in advance!
-Mary
December 10, 2010 at 12:55 am #27241amin007ParticipantLet me know if this helps at all… Set the “Products Per Page Limit” settings option to 3.
Now everywhere you use the following shortcode it will show 3 items and the rest will be on the next pages (there will be a pagination):
[wp_eStore_category_products_fancy id=1 style=3 order=3]
December 10, 2010 at 2:11 am #27242MaryMemberHi Amin007,
Thank you for the reply!
Unfortunately this solution doesn’t work for me because there are other categories of products where I want to show more than 3 products. The situation where I want to show only 3 products is just for a certain category.
Any other thoughts? Maybe this is a crazy idea, but is there a way that I can change the wp_eStore_category_products_fancy function to include the number modifier?
Thanks again!
-Mary
December 10, 2010 at 3:53 am #27243amin007ParticipantYou will have to modify the code then. The file you need to look for is “shortcode_include.php” from the extra eStore shortcode plugin. This is the function that handles it:
function show_wp_eStore_category_products_fancy
At the moment it limits to the number of products per page set in the settings menu.
If this doesn’t work then the only way to handle this would be to add in a completely new shortcode that takes the number parameter.
December 10, 2010 at 1:42 pm #27244MaryMemberHoly Cow, Amin007, I did it!
You’re talking to someone who is NOT a programmer! I mean, really NOT. But, I was able to edit both the shortcode_include.php and eStore-extra-shortcodes.php to create a new shortcode that does exactly what I want!!!! I’m doing the happy dance!
In case anyone else is looking to do this, here’s what I did:
In the shortcode_include.php file, I copied the function called show_wp_eStore_category_products_fancy
and then changed the following beginning lines of the copied function from:
function show_wp_eStore_category_products_fancy($id,$style=3,$order=1)
{
if($id==’no id’)
{
return “You did not specify a category ID. Please enter a category ID with this shortcode”;
}
$i = 0;
//set pages to include $limit records per page
$limit = get_option(‘eStore_products_per_page’);
if(empty($limit))
$limit = 25;
if (isset($_GET))
{
$page = $_GET;
}
else
{
$page = 1;
to:
function show_wp_eStore_category_limitp_fancy($limit,$id,$style=3,$order=1)
{
if($id==’no id’)
{
return “You did not specify a category ID. Please enter a category ID with this shortcode”;
}
$i = 0;
if($limit==’no limit’)
$limit = 25;
if (isset($_GET))
{
$page = $_GET;
}
else
{
$page = 1;
}
And, then, in the file titled eStore-extra-shortcodes.php, I inserted a line in the ‘add shortcode’ section towards the top:
add_shortcode(‘wp_eStore_fancy1_no_price’, ‘eStore_fancy1_no_price’);
add_shortcode(‘wp_eStore_latest_products’, ‘wp_eStore_latest_products_handler’);
add_shortcode(‘wp_eStore_category_products_fancy’, ‘wp_eStore_category_products_fancy_handler’);
//MEK added this function
add_shortcode(‘wp_eStore_category_limitp_fancy’, ‘wp_eStore_category_limitp_fancy_handler’);
add_shortcode(‘wp_eStore_display_compact_cart’, ‘wp_eStore_display_compact_cart_handler’);
add_shortcode(‘wp_eStore_fancy1_video_thumbnail’, ‘wp_eStore_fancy1_video_thumbnail_handler’);
add_shortcode(‘wp_eStore_free_download_ajax_fancy’,’wp_eStore_free_download_ajax_fancy_handler’);
And then, in this same file, I copied the following lines:
function wp_eStore_category_products_fancy_handler($atts){
extract(shortcode_atts(array(
‘id’ => ‘no id’,
‘style’ => ‘1’,
‘order’ => ‘1’,
), $atts));
return show_wp_eStore_category_products_fancy($id,$style,$order);
}
and edited the copied lines to be:
//MEK added this function
function wp_eStore_category_limitp_fancy_handler($atts){
extract(shortcode_atts(array(
‘limit’ => ‘no limit’,
‘id’ => ‘no id’,
‘style’ => ‘1’,
‘order’ => ‘1’,
), $atts));
return show_wp_eStore_category_limitp_fancy($limit,$id,$style,$order);
}
and, now I have the shortcode:
[wp_eStore_category_limitp_fancy limit=3 id=1 style=3 order=1]
that limits the number of products within a category shown to 3 (or whatever).
How cool is that!
Thanks for all of your help, Amin007!
-Mary
December 10, 2010 at 2:04 pm #27245MaryMemberAlso, I was also able to remove the pagination by deleting the following lines from my new function, show_wp_eStore_category_limitp_fancy, in the file shortcode_include.php:
//Number of pages setup
if ($totalrows > $limit)
{
$pages = ceil($totalrows / $limit)+1;
$separator=’?’;
$url=get_permalink();
if(strpos($url,’?product_page=’))
{
$separator=’?’;
}
else if(strpos($url,’?’)!==false)
{
$separator=’&’;
}
$output .= ‘<div class=”product_page”>’;
for($r = 1;$r<$pages;$r++)
{
$output .= ‘‘.$r.’ ‘;
//$output .= ““.$r.” “;
if ($r%15==0)
$output .= ‘
‘;
}
Wooooo Hoooo!!!
Thnks again!
-Mary
December 10, 2010 at 11:18 pm #27246amin007ParticipantGreat Thank you for sharing the modifications.
-
AuthorPosts
- You must be logged in to reply to this topic.