Detail page is mostly working now
authorSteve Sutton <steve@gaslightmedia.com>
Tue, 21 Jun 2016 21:10:04 +0000 (17:10 -0400)
committerSteve Sutton <steve@gaslightmedia.com>
Tue, 21 Jun 2016 21:10:04 +0000 (17:10 -0400)
WIP pretty url now working with new detail short code

index.php
views/tour_detail.php

index 85179df..2a47ac5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -10,6 +10,7 @@
  */
 
 define( 'GLM_CUSTOM_POST_TYPE', 'france_tour' );
+define( 'GLM_CUSTOM_DETAIL_PAGE', 'tour-detail' );
 define( 'GLM_CUSTOM_TOUR_SINGLE', 'Tour' );
 define( 'GLM_CUSTOM_TOUR_PLURAL', 'Tours' );
 define( 'GLM_CUSTOM_CATEGORY_NAME', 'glm_custom_category' );
@@ -84,7 +85,7 @@ function glm_custom_custom_post_type() {
                'has_archive'           => true,
                'exclude_from_search'   => false,
                'publicly_queryable'    => true,
-               'rewrite'               => $rewrite,
+               'rewrite'               => false,
                'capability_type'       => 'page',
                'register_meta_box_cb'  => 'glm_custom_add_metaboxes',
        );
@@ -552,7 +553,15 @@ function glm_custom_get_terms_dropdown( $cat_id ) {
        return $output;
 }
 
-
+function glm_custom_detail_shortcode( $atts ) {
+    global $post;
+       extract( shortcode_atts( array( 'limit' => '10' ), $atts ) );
+       ob_start();
+       glm_custom_show_tour();
+       $output = ob_get_contents();
+       ob_end_clean();
+       return $output;
+}
 /**
  * Function glm_custom_list_tours
  *
@@ -598,7 +607,7 @@ function glm_custom_list_tours( $text_query ) {
             $tour->end = true;
         }
         //$cat->href  = '?glm_custom_category=';
-        $tour->href = site_url( '/' . GLM_CUSTOM_POST_TYPE . '/' . $tour->post_name .'/' );
+        $tour->href = site_url( '/' . GLM_CUSTOM_DETAIL_PAGE . '/' . $tour->post_name .'/' );
         ++$iterator;
     }
     include 'views/list_tours.php';
@@ -653,9 +662,11 @@ function glm_custom_list_categories( $cat_id = null ) {
  * @access public
  * @return void
  */
-function glm_custom_show_tour( $prod_id ) {
+function glm_custom_show_tour() {
        global $wpdb, $wp;
-       $tour = get_post( $prod_id );
+    $tour_slug = get_query_var('tour', '');
+    $tour = get_page_by_path( $tour_slug, ARRAY_A, GLM_CUSTOM_POST_TYPE );
+    echo '<pre>$tour: ' . print_r($tour, true) . '</pre>';
        include 'views/tour_detail.php';
        return;
 }
@@ -681,11 +692,12 @@ function glm_custom_show_category( $cat_id ) {
        return;
 }
 add_shortcode( GLM_CUSTOM_POST_TYPE, 'glm_custom_shortcode' );
+add_shortcode( GLM_CUSTOM_POST_TYPE . '-detail', 'glm_custom_detail_shortcode' );
 $rules = get_option( 'rewrite_rules' );
-if ( ! isset( $rules['(' . GLM_CUSTOM_POST_TYPE . ')/([^/]*)$'] ) ) {
+if ( ! isset( $rules['(' . GLM_CUSTOM_DETAIL_PAGE . ')/([^/]*)$'] ) ) {
     add_filter( 'rewrite_rules_array', function( $rules ){
         $newrules = array();
-        $newrules[''] = 'index.php?pagename=$matches[1]&tour=$matches[2]';
+        $newrules['(' . GLM_CUSTOM_DETAIL_PAGE . ')/([^/]*)$'] = 'index.php?pagename=$matches[1]&tour=$matches[2]';
         return $newrules + $rules;
     } );
 
@@ -695,6 +707,6 @@ if ( ! isset( $rules['(' . GLM_CUSTOM_POST_TYPE . ')/([^/]*)$'] ) ) {
     } );
 }
 add_filter( 'query_vars', function( $vars ) {
-    array_push( $vars, 'glm_custom_id' );
+    array_push( $vars, 'tour' );
     return $vars;
 } );
index 278712f..6e0c4eb 100644 (file)
@@ -1,41 +1,48 @@
-
 <?php
 $args = array(
-    'orderby' => 'parent',
-    'hierarchical'=> true,
+    'orderby'      => 'parent',
+    'hierarchical' => true,
 );
-$relatives = wp_get_post_terms($product->ID, 'michsci_category', $args);
+$relatives = wp_get_post_terms( $tour->ID, GLM_CUSTOM_CATEGORY_NAME, $args );
+echo '<pre>$relatives: ' . print_r($relatives, true) . '</pre>';
 ?>
 <div class="small-12 medium-6" id="productBreadcrumbs">
  <?php echo '<a href="'. get_permalink(510) .  '">' . Products . '</a>'." > "; ?>
-<?php foreach($relatives as $relative){
-    echo '<a href="'.  '?michsci_category=' . $relative->term_id . '" >' . $relative->name . "</a>" . " > ";
-} ?>
-    <?php echo $product->post_title . "<br>"; ?>
+<?php if ( isset( $relatives ) ) {
+    foreach ( $relatives as $relative ) {
+        echo '<a href="'.  '?michsci_category=' . $relative->term_id . '" >' . $relative->name . "</a>" . " > ";
+    } 
+}?>
+    <?php echo $tour->post_title . "<br>"; ?>
 </div>
-<h2><?php echo $product->post_title; ?></h2>
+<h2><?php echo $tour->post_title; ?></h2>
 
 <div class="row">
     <div class="productImage small-12 medium-4 columns">
-           <?php echo get_the_post_thumbnail($product->ID, 'large'); ?>
+           <?php echo get_the_post_thumbnail($tour->ID, 'large'); ?>
     </div>
     <div class="features small-12 medium-4 columns">
-         <?php
-         echo '<h2> Features </h2>';
-            $key_value = get_post_custom_values('miproduct_features', $product->ID); 
-            foreach($key_value as $key=>$value){
+        <?php
+        echo '<h2> Features </h2>';
+        $key_value = get_post_custom_values('glm_custom_features', $tour->ID); 
+        if ( $key_value ) {
+            foreach ($key_value as $key=>$value) {
                 $shortcode_output = do_shortcode($value);
                 print $shortcode_output;
-        }?>
+            }
+        }
+        ?>
     </div>
  
     <div id="relatedFiles" class='small-12 medium-4 columns'>
         <h3> Related Files </h3>
         <?php
-            $key_value = get_post_custom_values('miproduct_related_products', $product->ID); 
+        $key_value = get_post_custom_values('glm_custom_related_products', $tour->ID); 
+        if ( $key_value && is_array( $key_value ) ) {
             foreach($key_value as $key=>$value){
                 $shortcode_output = do_shortcode($value);
                 print $shortcode_output;
+            }
         }?>
          <div class="gallery ">
           <?php echo '<h4><a class="galleryLink" href="#glm_gallery"> Product Gallery </a></h4>'; ?>
@@ -44,7 +51,7 @@ $relatives = wp_get_post_terms($product->ID, 'michsci_category', $args);
                 $args = array(
                 "hide_empty"=>false
             );
-            $tags = wp_get_post_terms($product->ID,'michsci_tag', $args);
+            $tags = wp_get_post_terms($tour->ID,GLM_CUSTOM_TAG_NAME, $args);
             foreach ($tags as $tag){ ?>
                 <?php echo '<a id="' . $tag->slug . '"href="'.  get_permalink(510) . '">'. $tag->name . '</a>' . "<br>"; ?> 
             <?php }?>
@@ -54,8 +61,8 @@ $relatives = wp_get_post_terms($product->ID, 'michsci_category', $args);
     </div>
     <div class="description small-12 medium-7 columns">
         <?php
-            setup_postdata( $product );
-            the_content(); 
+            setup_postdata( $tour );
+            echo apply_filters('the_content', $tour->post_content); 
         ?>
     </div>