Page 1 of 1
Noob needs a hand...
Posted: Tue Jul 12, 2011 1:38 pm
by manley91
Hi there,
I have a script which is part of a wordpress site I'm working on, basically, the script creates price ranges and then displays the price ranges as links.
I want to change it, so that it creates the ranges, but doesn't display them, so that I can then just manually link to the pages it creates through the menu.
Here's the code:
http://tinypaste.com/28fe2f
If anyone could give me a hand on editing it to not display the links that would be awesome!
I've tried messing around with it for a while but I can getting fatal errors, as I don't know PHP well at all!
Thanks in advance

Re: Noob needs a hand...
Posted: Tue Jul 12, 2011 1:49 pm
by social_experiment
If you could paste the code here we could give you advice on it
Re: Noob needs a hand...
Posted: Tue Jul 12, 2011 1:57 pm
by manley91
Hi,
Sorry- here's the code
Code: Select all
<?php
function widget_price_range($args) {
global $wpdb, $table_prefix;
extract($args);
$options = get_option('wpsc-widget_price_range');
$title = empty($options['title']) ? __(__('Price Range', 'wpsc')) : $options['title'];
echo $before_widget."";
$full_title = $before_title . $title . $after_title;
echo $full_title."";
nzshpcrt_price_range();
echo $after_widget;
}
function nzshpcrt_price_range($input = null) {
global $wpdb;
$siteurl = get_option('siteurl');
$product_page=get_option("product_list_url");
if (stristr($product_page,"?")) {
$seperater='&';
} else {
$seperater='?';
}
$result = $wpdb->get_results("SELECT DISTINCT `price` FROM ".WPSC_TABLE_PRODUCT_LIST." WHERE `active` IN ('1') ORDER BY price ASC",ARRAY_A);
if($result != null) {
sort($result);
$count = count($result);
$price_seperater = ceil($count/6);
for($i=0;$i<$count;$i+=$price_seperater) {
$ranges[]=round($result[$i]['price'],-1);
}
$ranges = array_unique($ranges);
$final_count = count($ranges);
$ranges = array_merge(array(0,50,75,100,150,200));
$_SESSION['price_range']=$ranges;
// echo('<pre>'.print_r($ranges, true).'</pre>');
for($i=0;$i<$final_count;$i++) {
$j=$i;
if ($i==$final_count-1) {
echo "<a href='".htmlentities($product_page.$seperater."range=".$j)."'>Over ".nzshpcrt_currency_display($ranges[$i],1,true)."</a><br/>";
} else if($ranges[$i]==0){
echo "<a href='".htmlentities($product_page.$seperater."range=".$j)."'>Under ".nzshpcrt_currency_display($ranges[$i+1],1,true)."</a><br/>";
}else {
echo "<a href='".htmlentities($product_page.$seperater."range=".$j)."'>".nzshpcrt_currency_display($ranges[$i],1,true)." - ".nzshpcrt_currency_display($ranges[$i+1],1,true)."</a><br/>";
}
}
if(get_option('permalink_structure') != '') {
$seperator ="?";
} else {
$seperator ="&";
}
echo "<a href='".get_option("product_list_url").$seperator."range=all'>".__('Show All', 'wpsc')."</a><br/>";
}
}
function widget_price_range_control() {
$option_name = 'wpsc-widget_price_range'; // because I want to only change this to reuse the code.
$options = $newoptions = get_option($option_name);
if ( isset($_POST[$option_name]) ) {
$newoptions['title'] = strip_tags(stripslashes($_POST[$option_name]));
}
if ( $options != $newoptions ) {
$options = $newoptions;
update_option($option_name, $options);
}
$title = htmlspecialchars($options['title'], ENT_QUOTES);
echo "<p>\n\r";
echo " <label for='{$option_name}'>"._e('Title:')."<input class='widefat' id='{$option_name}' name='{$option_name}' type='text' value='{$title}' /></label>\n\r";
echo "</p>\n\r";
}
function widget_price_range_init() {
if(function_exists('register_sidebar_widget')) {
register_sidebar_widget(__('Price Range', 'wpsc'), 'widget_price_range');
register_widget_control(__('Price Range', 'wpsc'), 'widget_price_range_control');
}
return;
}
add_action('plugins_loaded', 'widget_price_range_init');
?>
Re: Noob needs a hand...
Posted: Tue Jul 12, 2011 2:07 pm
by social_experiment
Code: Select all
<?php
function nzshpcrt_price_range($input = null) {
global $wpdb;
$siteurl = get_option('siteurl');
$product_page=get_option("product_list_url");
if (stristr($product_page,"?")) {
$seperater='&';
} else {
$seperater='?';
}
$result = $wpdb->get_results("SELECT DISTINCT `price` FROM ".WPSC_TABLE_PRODUCT_LIST." WHERE `active` IN ('1') ORDER BY price ASC",ARRAY_A);
if($result != null) {
sort($result);
$count = count($result);
$price_seperater = ceil($count/6);
for($i=0;$i<$count;$i+=$price_seperater) {
$ranges[]=round($result[$i]['price'],-1);
}
$ranges = array_unique($ranges);
$final_count = count($ranges);
$ranges = array_merge(array(0,50,75,100,150,200));
$_SESSION['price_range']=$ranges;
/*
// echo('<pre>'.print_r($ranges, true).'</pre>');
for($i=0;$i<$final_count;$i++) {
$j=$i;
if ($i==$final_count-1) {
echo "<a href='".htmlentities($product_page.$seperater."range=".$j)."'>Over ".nzshpcrt_currency_display($ranges[$i],1,true)."</a><br/>";
} else if($ranges[$i]==0){
echo "<a href='".htmlentities($product_page.$seperater."range=".$j)."'>Under ".nzshpcrt_currency_display($ranges[$i+1],1,true)."</a><br/>";
}else {
echo "<a href='".htmlentities($product_page.$seperater."range=".$j)."'>".nzshpcrt_currency_display($ranges[$i],1,true)." - ".nzshpcrt_currency_display($ranges[$i+1],1,true)."</a><br/>";
}
}
if(get_option('permalink_structure') != '') {
$seperator ="?";
} else {
$seperator ="&";
}
echo "<a href='".get_option("product_list_url").$seperator."range=all'>".__('Show All', 'wpsc')."</a><br/>";
}*/
}
?>
If you echo out the lines above in the given function, what happens?
Re: Noob needs a hand...
Posted: Tue Jul 12, 2011 3:44 pm
by manley91
It works perfectly- exactly what I was after- thanks.