From 5c3b35fc6d0c4be2355ec8fa81ea9831a732417f Mon Sep 17 00:00:00 2001 From: Chiranjit Makur Date: Thu, 5 May 2016 18:18:43 +0530 Subject: [PATCH 1/3] added admin option to change post order ASC or DESC --- threads.php | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/threads.php b/threads.php index 3945e6f..77c0404 100644 --- a/threads.php +++ b/threads.php @@ -135,12 +135,14 @@ function cfth_thread_notice($posts, $query) { function cfth_timeline_posts($term_id) { $term = get_term_by('id', $term_id, 'threads'); + $term_meta = get_term_meta( $term_id, 'threads_meta', true ); + $order = ( isset( $term_meta['order_term_meta'] )) ? $term_meta['order_term_meta'] : 'ASC'; if ($term) { $query_params = apply_filters('threads_timeline_posts_query', array( 'posts_per_page' => -1, 'taxonomy' => 'threads', 'term' => $term->slug, - 'order' => 'ASC', + 'order' => $order, )); $query = new WP_Query($query_params); return $query->posts; @@ -149,6 +151,9 @@ function cfth_timeline_posts($term_id) { } function cfth_timeline_content($term_id) { + $term = get_term_by('id', $term_id, 'threads'); + $term_meta = get_term_meta( $term_id, 'threads_meta', true ); + $order = ( isset( $term_meta['order_term_meta'] )) ? $term_meta['order_term_meta'] : 'ASC'; $posts = cfth_timeline_posts($term_id); if (!count($posts)) { return array(); @@ -170,7 +175,7 @@ function cfth_timeline_content($term_id) { if ($prev) { $prev_timestamp = strtotime($prev->post_date_gmt); $this_timestamp = strtotime($_post->post_date_gmt); - $prev->threads_data['time_offset'] = $this_timestamp - $prev_timestamp; + $prev->threads_data['time_offset'] = ( isset( $term_meta['order_term_meta'] ) && 'DESC' === $term_meta['order_term_meta']) ? $prev_timestamp - $this_timestamp : $this_timestamp - $prev_timestamp; } $prev = $_post; } @@ -375,3 +380,58 @@ function cfth_timeline_css() { +
+ + +

+
+term_id, 'threads_meta', true ); + ?> + + + + + +

+ + + Date: Thu, 5 May 2016 19:00:37 +0530 Subject: [PATCH 2/3] Updated metavalue --- threads.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/threads.php b/threads.php index 77c0404..1643979 100644 --- a/threads.php +++ b/threads.php @@ -419,7 +419,7 @@ function threads_taxonomy_edit_meta_field( $term ) { // Save meta field for thread taxonomy. function save_threads_custom_meta( $term_id ) { if ( isset( $_POST['term_meta'] ) ) { - $term_meta = get_option( "threads_meta" ); + $term_meta = get_term_meta( $term_id, 'threads_meta', true ); $cat_keys = array_keys( $_POST['term_meta'] ); foreach ( $cat_keys as $key ) { From cf585df7c5ae56456de80aca397c0b6d497e5b02 Mon Sep 17 00:00:00 2001 From: Chiranjit Makur Date: Fri, 6 May 2016 18:45:32 +0530 Subject: [PATCH 3/3] Updated as per the comments in PR --- README.txt | 4 +-- threads.php | 81 +++++++++++++++++++++++++++++++++-------------------- 2 files changed, 52 insertions(+), 33 deletions(-) diff --git a/README.txt b/README.txt index b50104c..f1f3353 100644 --- a/README.txt +++ b/README.txt @@ -1,8 +1,8 @@ === Plugin Name === Contributors: alexkingorg, crowdfavorite Tags: content, timeline, display, presentation, story, storyline, context -Requires at least: 3.5 -Tested up to: 3.5.1 +Requires at least: 4.4.0 +Tested up to: 4.5.1 Stable tag: 1.0b1 License: GPLv2 License URI: http://www.gnu.org/licenses/gpl-2.0.html diff --git a/threads.php b/threads.php index 1643979..57c2093 100644 --- a/threads.php +++ b/threads.php @@ -135,8 +135,10 @@ function cfth_thread_notice($posts, $query) { function cfth_timeline_posts($term_id) { $term = get_term_by('id', $term_id, 'threads'); - $term_meta = get_term_meta( $term_id, 'threads_meta', true ); - $order = ( isset( $term_meta['order_term_meta'] )) ? $term_meta['order_term_meta'] : 'ASC'; + if ( function_exists( 'get_term_meta' ) ) { + $term_meta = get_term_meta( $term_id, 'threads_meta', true ); + } + $order = isset( $term_meta['order_term_meta'] ) ? $term_meta['order_term_meta'] : 'ASC'; if ($term) { $query_params = apply_filters('threads_timeline_posts_query', array( 'posts_per_page' => -1, @@ -152,8 +154,10 @@ function cfth_timeline_posts($term_id) { function cfth_timeline_content($term_id) { $term = get_term_by('id', $term_id, 'threads'); - $term_meta = get_term_meta( $term_id, 'threads_meta', true ); - $order = ( isset( $term_meta['order_term_meta'] )) ? $term_meta['order_term_meta'] : 'ASC'; + if ( function_exists( 'get_term_meta' ) ) { + $term_meta = get_term_meta( $term_id, 'threads_meta', true ); + } + $order = isset( $term_meta['order_term_meta'] ) ? $term_meta['order_term_meta'] : 'ASC'; $posts = cfth_timeline_posts($term_id); if (!count($posts)) { return array(); @@ -175,7 +179,14 @@ function cfth_timeline_content($term_id) { if ($prev) { $prev_timestamp = strtotime($prev->post_date_gmt); $this_timestamp = strtotime($_post->post_date_gmt); - $prev->threads_data['time_offset'] = ( isset( $term_meta['order_term_meta'] ) && 'DESC' === $term_meta['order_term_meta']) ? $prev_timestamp - $this_timestamp : $this_timestamp - $prev_timestamp; + + if( isset( $term_meta['order_term_meta'] ) && 'DESC' === $term_meta['order_term_meta'] ) { + // offset calculation if post order selected as DESC. + $prev->threads_data['time_offset'] = $prev_timestamp - $this_timestamp; + } else { + // offset calculation if post order selected as ASC. + $prev->threads_data['time_offset'] = $this_timestamp - $prev_timestamp; + } } $prev = $_post; } @@ -380,58 +391,66 @@ function cfth_timeline_css() {
-

+

term_id, 'threads_meta', true ); +/** + * Meta field markup for edit thread page. + * + * @since 1.0b1 + */ +function cfth_taxonomy_edit_meta_field( $term ) { + if ( function_exists( 'get_term_meta' ) ) { + $term_meta = get_term_meta( $term->term_id, 'threads_meta', true ); + } ?> -

+