From 75ce51e8e8bebf9a1239eab1e1de1c81b1502cd7 Mon Sep 17 00:00:00 2001 From: Steve Sutton Date: Tue, 21 Jun 2016 17:10:04 -0400 Subject: [PATCH] Detail page is mostly working now WIP pretty url now working with new detail short code --- index.php | 28 +++++++++++++++++++-------- views/tour_detail.php | 45 +++++++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/index.php b/index.php index 85179df..2a47ac5 100644 --- 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 '
$tour: ' . print_r($tour, true) . '
'; 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; } ); diff --git a/views/tour_detail.php b/views/tour_detail.php index 278712f..6e0c4eb 100644 --- a/views/tour_detail.php +++ b/views/tour_detail.php @@ -1,41 +1,48 @@ - '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 '
$relatives: ' . print_r($relatives, true) . '
'; ?>
' . Products . ''." > "; ?> -term_id . '" >' . $relative->name . "" . " > "; -} ?> - post_title . "
"; ?> +term_id . '" >' . $relative->name . "" . " > "; + } +}?> + post_title . "
"; ?>
-

post_title; ?>

+

post_title; ?>

- ID, 'large'); ?> + ID, 'large'); ?>
- Features '; - $key_value = get_post_custom_values('miproduct_features', $product->ID); - foreach($key_value as $key=>$value){ + Features '; + $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; - }?> + } + } + ?>

Related Files

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; + } }?>
post_content); ?>
-- 2.17.1