add_shortcode('glmcoupons', array($this, 'glm_coupon_shortcode'));
$this->viewDir = $this->pluginDirName . self::FORM_VIEW_DIR;
$this->frontViewDir = $this->viewDir . '/front';
+ add_action('wp_enqueue_scripts', array($this, 'load_stylesheet'));
}
public function glm_coupon_shortcode($atts)
// use smarty template to output the form
}
+ public function load_stylesheet()
+ {
+ wp_enqueue_style(
+ 'glm-coupons',
+ plugins_url('glm-coupons/css/front/coupons.css' , $this->pluginDirName),
+ array(),
+ '0.0.1',
+ 'all'
+ );
+ }
+
public function list_coupons()
{
global $wpdb, $wp;
);
}
}
+ $categories = array();
$coupons = get_posts($args);
- $totalCoupons = count($coupons);
- $iterator = 1;
+ //$totalCoupons = count($coupons);
+ //$iterator = 1;
foreach ($coupons as $coupon) {
$custom = get_post_custom($coupon->ID);
$coupon->end = false;
$coupon->glm_coupons_enddate = $custom['glm_coupons_enddate'][0];
$coupon->glm_coupons_expdate = $custom['glm_coupons_expdate'][0];
$coupon->glm_coupons_url = $custom['glm_coupons_url'][0];
- if ($iterator == $totalCoupons) {
- $coupon->end = true;
+ $coupon->glm_coupons_thumb = get_the_post_thumbnail($coupon->ID, 'thumbnail', array('class' => 'aligncenter'));
+ $post_categories = wp_get_object_terms(
+ $coupon->ID,
+ GLM_COUPON_TAX_CATEGORIES,
+ array('fields' => 'names')
+ );
+ //var_dump($post_categories);
+ foreach ($post_categories as $category) {
+ //$cat = get_category($c);
+ $coupon->categoryName = $category;
+ $categories[$category][] = $coupon;
}
- ++$iterator;
+
+ //if ($iterator == $totalCoupons) {
+ //$coupon->end = true;
+ //}
+ //++$iterator;
}
include $this->frontViewDir . '/couponList.php';
return;
+.coupon-row {
+ display: block;
+ width: 100%;
+}
+.coupon-item {
+ display: inline-table;
+ width: 30%;
+ padding: 0;
+ margin: 5px;
+ border: 1px dashed lightgrey;
+}
+.coupon-item-wrap {
+ padding: 20px;
+}
+.coupon-row h2 {
+ font-size: 1.45rem;
+}
+.coupon-row h3 {
+ font-size: 1.3rem;
+}
+.coupon-expires {
+ margin: 20px 5px 5px 0;
+ float: right;
+ font-size: .8rem;
+}
+.coupon-descr {
+ font-size: .9rem;
+}
+.coupon-url {
+ float: left;
+ font-size: .8rem;
+ margin: 20px 0 5px 5px;
+}
+.coupon-select {
+ background-color: lightgrey;
+ width: 100%;
+ height: 40px;
+ padding: 10px;
+}
+
+@media screen and (max-width: 40em) {
+ .coupon-item {
+ width: 100%;
+ }
+}
+@media screen and (min-width: 40.63em) and (max-width: 64em) {
+ .coupon-item {
+ width: 45%;
+ }
+}
'public' => true,
'can_export' => true,
'menu_position' => 21,
- 'supports' => array('title', 'editor'),
+ 'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'author'),
'has_archive' => true,
'menu_icon' => 'dashicons-products',
'capability_type' => 'post',
</li>
<li>
<label>Url:</label>
- <input name="glm_coupon_url"
- value="<?php echo $glm_coupon_url; ?>" />
+ <input name="glm_coupons_url"
+ value="<?php echo $glm_coupons_url[0]; ?>" />
</li>
</ul>
</div>
<div>
<h1>List Coupons</h1>
+ <?php if ($categories) : foreach ($categories as $catName => $coupons) :?>
+ <h2><?php echo $catName;?></h2>
<div class="coupon-row">
<?php if ($coupons): foreach($coupons as $coupon) :?>
- <div class="<?php if ($coupon->end){ echo ' end';}?> coupon-item">
- <h2><?php echo $coupon->post_title;?></h2>
- <div><?php echo $coupon->post_content;?></div>
- <div><b>Expires:</b> <?php echo date('F d,Y', $coupon->glm_coupons_expdate);?></div>
+ <div class="<?php if ($coupon->end){ echo ' end';}?> coupon-item">
+ <div class="coupon-select"><label><input type="checkbox" name="coupon-id-<?php echo $coupon->ID;?>"> Select this coupon</label></div>
+ <div class="coupon-item-wrap">
+ <h3><?php echo $coupon->post_title;?></h3>
+ <?php if ($coupon->glm_coupons_thumb) : ?>
+ <?php echo $coupon->glm_coupons_thumb;?>
+ <?php endif;?>
+ <div class="coupon-descr"><?php echo $coupon->post_content;?></div>
+ <?php if ($coupon->glm_coupons_url) :?>
+ <div class="coupon-url"><a href="<?php echo date('F d,Y', $coupon->glm_coupons_url);?>">Web Site</a></div>
+ <?php endif;?>
+ <div class="coupon-expires"><b>Expires:</b> <?php echo date('m/d/Y', $coupon->glm_coupons_expdate);?></div>
+ </div>
+ </div>
+ <?php endforeach; endif;?>
</div>
<?php endforeach; endif;?>
- </div>
</div>