Hello all,
It’s been a while since I have been on here and I am glad y’all are still going strong. I still see NogDog is here and he has helped me so freaking much in the past! AWESOME!
`
Anyways, I am passing a variable via the URL and have had no problem. However, the variable is being passed to a page template called ‘product’ which displays a single product out of a catalog. The variable being passed is the slug name of the product that was selected from the catalog.
My catalog is a widget I developed to display a gallery of my products and also their custom fields which can be changed within the widget area. ANYWAYS, this is NOT a POST so I can’t use the get_post() approach! I need to query one particular product out of my catalog and it’s attributes so I can display it singularly on a page.
ESSENTIALLY:
When viewer clicks product from a catalog, site sends the slug name of that product via the URL to the product page ([url]http://localhost:8888/wordpress/product/?id=my-product-name
My code for the product page:
[CODE]
<?php
if(isset($wp_query->query_vars[‘id’])) {
$product = urldecode($wp_query->query_vars[‘id’]);
}
echo $product;
?>
<div class=”grid-catalog”>
<div class=”site-catalog”>
<ul>
<!– CATALOG –>
<?php
if( dynamic_sidebar(‘catalog’)) : else : endif;
?>
</ul>
</div>
</div>
?>
As of now, this doesn’t do anything but take you to the products page and show you the entire catalog just as you were looking at on the previous page. My goal is to query this catalog and display only the product that is in the URL variable.
Anyways, here is my catalog plugin/widget code:
[CODE]
<?php
/* This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Copyright 2016 Brad Harrell Design
*/
/*
Plugin Name: Troph Catalog
Plugin URI: http://www.bradharrell.com
Description: Add Brad Harrell’s catalog widget to your theme
Version 1.0
Author: Brad
Author: http://www.bradharrell.com
*/
function troph_catalog_widget(){
register_widget(‘troph_catalog_widget’);
}
add_action(‘widgets_init’, ‘troph_catalog_widget’);
class troph_catalog_widget extends WP_Widget
{
function troph_catalog_widget(){
//process widget
$widget_options = array(
‘classname’=> ‘troph_catalog_widget_classname’,
‘description’=> ‘A simple widget to show a catalog.’,
);
$this->WP_Widget(‘troph_catalog_widget’, ‘Troph Catalog Widget’, $widget_options);
}
function form($instance){
//show widget form in admin panel
$default_settings = array(
‘title’=>”,
‘slug’=>”,
‘imgLink’ => ”,
‘imgAlt’=>”,
‘price’=>”,
‘productType’=>”,
);
$instance = wp_parse_args(
(array) $instance,
$default_settings
);
$title = $instance[‘title’];
$slug = $instance[‘slug’];
$imgLink = $instance[‘imgLink’];
$imgAlt = $instance[‘imgAlt’];
$price = $instance[‘price’];
$productType = $instance[‘productType’];
?>
<p>Title: <input class=”widefat”
name=”<?php echo $this->get_field_name(‘title’) ?>”
type=”text” value=”<?php echo esc_attr($title)?>”/>
</p>
<p>Slug: <input class=”widefat”
name=”<?php echo $this->get_field_name(‘slug’) ?>”
type=”text” value=”<?php echo esc_attr($slug)?>”/>
</p>
<p>Img Link: <input class=”widefat”
name=”<?php echo $this->get_field_name(‘imgLink’) ?>”
type=”text” value=”<?php echo esc_attr($imgLink)?>”/>
</p>
<p>Img Alt: <input class=”widefat”
name=”<?php echo $this->get_field_name(‘imgAlt’) ?>”
type=”text” value=”<?php echo esc_attr($imgAlt)?>”/>
</p>
<p>Price: <input class=”widefat”
name=”<?php echo $this->get_field_name(‘price’) ?>”
type=”text” value=”<?php echo esc_attr($price)?>”/>
</p>
<p>Product Type:
<select class=”widefat” name=”<?php echo $this->get_field_name(‘productType’) ?>”>
<option value=”awards”>Awards</option>
<option value=”collections”>Collections</option>
<option value=”gifts”>Gifts</option>
<option value=”stationery”>Stationery</option>
<option value=”custom”>Custom</option>
</select>
</p>
<?php
}
function update($new_instance, $old_instance)
{
//update widget settings
$instance = $old_instance;
$instance[‘title’] = $new_instance[‘title’];
$instance[‘slug’] = $new_instance[‘slug’];
$instance[‘imgLink’] = strip_tags($new_instance[‘imgLink’]);
$instance[‘imgAlt’] = $new_instance[‘imgAlt’];
$instance[‘price’] = $new_instance[‘price’];
$instance[‘productType’] = $new_instance[‘productType’];
return $instance;
}
function widget($args, $instance)
{
//display widget
extract($args);
$title = apply_filters(‘widget_title’, $instance[‘title’]);
$slug = empty($instance[‘slug’]) ? ” : $instance[‘slug’];
$imgLink = empty($instance[‘imgLink’]) ? ” : $instance[‘imgLink’];
$imgAlt = empty($instance[‘imgAlt’]) ? ” : $instance[‘imgAlt’];
$price = empty($instance[‘price’]) ? ” : $instance[‘price’];
$productType = empty($instance[‘productType’]) ? ” : $instance[‘productType’];
echo ‘
<li>
<a href=”product/index.php?id=geometria-rectangulus”>
<img src=”../wp-content/themes/trophyology/’.$imgLink.'”alt=”‘.$imgAlt.'”>
</a>
<i class=”grid”><a href=”#” class=”award-name”>’.$title.'<span class=”price”>’.$price.'</span></a></i>
<i class=”stream”><div class=”award-name”><a href=”#” class=”pin”></a><a href=”#” class=”title-link”>’.$title.'</a><span class=”price”>’.$price.'</span><a href=”#” class=”purchase”>Purchase</a><a href=”#” class=”details-link”>More Details</a></div></i>
</li>
‘;
}
}
?>