From b9efd611168cd985ae9038baa26415075850445e Mon Sep 17 00:00:00 2001 From: Jonathan Hult Date: Wed, 17 May 2017 12:57:11 -0400 Subject: [PATCH] Allow date modified - billerickson/display-posts-shortcode#132 --- README.md | 305 ++++++++++++++++++------------------ display-posts-shortcode.php | 9 +- 2 files changed, 162 insertions(+), 152 deletions(-) diff --git a/README.md b/README.md index 32d6949..5a4b437 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Display Posts Shortcode # -**Contributors:** billerickson -**Donate link:** https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MQKRBRFVRUV8C -**Tags:** shortcode, pages, posts, page, query, display, list -**Requires at least:** 3.0 -**Tested up to:** 4.6.0 -**Stable tag:** 2.7.0 +**Contributors:** billerickson +**Donate link:** https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MQKRBRFVRUV8C +**Tags:** shortcode, pages, posts, page, query, display, list +**Requires at least:** 3.0 +**Tested up to:** 4.6.0 +**Stable tag:** 2.7.0 Display a listing of posts using the [display-posts] shortcode @@ -29,129 +29,134 @@ Add the shortcode in a post or page, and use the arguments to query based on tag ## Parameters ## -**author** -Specify the post author -Default: empty +**author** +Specify the post author. +Default: empty Example: [display-posts author="bill"] -**category** -Specify the category slug, or comma separated list of category slugs -Default: empty -Example: [display-posts category="fishing,hiking"] - -**category_display** -Specify 'true' to display the categories the current post is in. Specify a taxonomy slug (e.g., 'post_tag') to list a different taxonomy -Default: empty -Example: [display-posts category_display="true"] - -**category_label** -If using category_display, specify the label that appears before the list of categories. -Default: "Posted in: " -Example: [display-posts category_display="true" category_label="Categorized as: "] - -**content_class** -Specify the class name used for the post content -Default: content -Example: [display-posts include_content="true" content_class="dps-listing-content"] - -**date_format** -Specify the date format used when include_date is true. See [Formatting Date and Time](http://codex.wordpress.org/Formatting_Date_and_Time) on the Codex for more information. -Default: '(n/j/Y)' -Example: [display-posts include_date="true" date_format="F j, Y"] - -**date** -Specify a date to query for posts published that date. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: empty -Example: [display-posts date="2014-09-07"] - -**date_column** -Specify which date column to use for all date queries. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: post_date -Example: [display-posts date="Yesterday" date_column="post_modified_date"] - -**date_compare** -Specify the comparison operator used for all date queries. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: = -Example: [display-posts date="-1 year" date_compare=">"] - -**date_query_before** -Specify the before argument for a date query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: empty +**category** +Specify the category slug, or comma separated list of category slugs. +Default: empty +Example: [display-posts category="fishing,hiking"] + +**category_display** +Specify 'true' to display the categories the current post is in. Specify a taxonomy slug (e.g., 'post_tag') to list a different taxonomy. +Default: empty +Example: [display-posts category_display="true"] + +**category_label** +If using category_display, specify the label that appears before the list of categories. +Default: "Posted in: " +Example: [display-posts category_display="true" category_label="Categorized as: "] + +**content_class** +Specify the class name used for the post content. +Default: content +Example: [display-posts include_content="true" content_class="dps-listing-content"] + +**date_format** +Specify the date format used when 'include_date' or 'include_date_modified' is true. See [Formatting Date and Time](http://codex.wordpress.org/Formatting_Date_and_Time) on the Codex for more information. +Default: '(n/j/Y)' +Example: [display-posts include_date="true" date_format="F j, Y"] + +**date** +Specify a date to query for posts published that date. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: empty +Example: [display-posts date="2014-09-07"] + +**date_column** +Specify which date column to use for all date queries. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: post_date +Example: [display-posts date="Yesterday" date_column="post_modified_date"] + +**date_compare** +Specify the comparison operator used for all date queries. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: = +Example: [display-posts date="-1 year" date_compare=">"] + +**date_query_before** +Specify the before argument for a date query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: empty Example: [display-posts date_query_before="2015-12-31" date_query_after="2015-01-01"] -**date_query_after** -Specify the after argument for a date query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: empty +**date_query_after** +Specify the after argument for a date query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: empty Example: [display-posts date_query_before="2015-12-31" date_query_after="2015-01-01"] -**date_query_column** -Specify the date column used for this query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: post_date +**date_query_column** +Specify the date column used for this query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: post_date Example: [display-posts date="Yesterday" date_query_column="post_modified_date"] -**date_query_compare** -Specify the comparison operator used for this query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: = +**date_query_compare** +Specify the comparison operator used for this query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: = Example: [display-posts date="-1 year" date_query_compare=">"] -**excerpt_length** -Specify the number of words used in an excerpt. [More information](https://github.com/billerickson/display-posts-shortcode/issues/110) -Default: empty (set by your theme) +**excerpt_length** +Specify the number of words used in an excerpt. [More information](https://github.com/billerickson/display-posts-shortcode/issues/110). +Default: empty (set by your theme) Example: [display-posts include_excerpt="true" excerpt_length="20"] -**excerpt_more** -Specify the more text that appears after the excerpt. -Default: empty (set by your theme) +**excerpt_more** +Specify the more text that appears after the excerpt. +Default: empty (set by your theme) Example: [display-posts include_excerpt="true" excerpt_more="..."] -**excerpt_more_link** -Specify whether or not to link the excerpt_more text to the post -Default: false +**excerpt_more_link** +Specify whether or not to link the excerpt_more text to the post. +Default: false Example: [display-posts include_excerpt="true" excerpt_more="Continue Reading" excerpt_more_link="true"] -**exclude_current** -Specify whether or not to exclude the current post from the query -Default: false +**exclude_current** +Specify whether or not to exclude the current post from the query. +Default: false Example: [display-posts exclude_current="true" taxonomy="category" tax_term="current"] -**id** -Specify a specific post ID (or multiple post IDs) to display. -Default: empty +**id** +Specify a specific post ID (or multiple post IDs) to display. +Default: empty Example: [display-posts id="9, 10"] -**ignore_sticky_posts** -Specify whether or not to ignore sticky posts -Default: false -Example: [displa-posts ignore_sticky_posts="true"] +**ignore_sticky_posts** +Specify whether or not to ignore sticky posts. +Default: false +Example: [display-posts ignore_sticky_posts="true"] -**image_size** -Specify an image size for displaying the featured image, if the post has one. The image_size can be set to thumbnail, medium, large (all controlled from Settings > Media), or a [custom image size](https://developer.wordpress.org/reference/functions/add_image_size/). See [Image Alignment](https://github.com/billerickson/display-posts-shortcode/wiki#image-alignment) -Default: empty +**image_size** +Specify an image size for displaying the featured image, if the post has one. The image_size can be set to thumbnail, medium, large (all controlled from Settings > Media), or a [custom image size](https://developer.wordpress.org/reference/functions/add_image_size/). See [Image Alignment](https://github.com/billerickson/display-posts-shortcode/wiki#image-alignment) +Default: empty Example: [display-posts image_size="thumbnail"] -**include_author** -Specify whether or not to include the post's author name. -Default: false +**include_author** +Specify whether or not to include the post's author name. +Default: false Example: [display-posts include_author="true"] -**include_content** -Specify whether or not to include the full post content. Note that [display-posts] will be stripped out of the content to prevent infinite loops -Default: false +**include_content** +Specify whether or not to include the full post content. Note that [display-posts] will be stripped out of the content to prevent infinite loops +Default: false Example:[display-posts include_content="true"] -**include_date** -Include the post's date after the post title. The default format is (7/30/12), but this can be customized using the 'date_format' parameter. -Default: empty +**include_date** +Include the post's date after the post title. The default format is (7/30/12), but this can be customized using the 'date_format' parameter. +Default: empty Example [display-posts include_date="true"] -**include_excerpt** -Include the post's excerpt after the title (and date if provided). -Default: empty +**include_date_modified** +Include the post's last modified date after the post title. The default format is (7/30/12), but this can be customized using the 'date_format' parameter. Note that this can only be used if 'include_date' is not true. +Default: empty +Example [display-posts include_date_modified="true"] + +**include_excerpt** +Include the post's excerpt after the title (and date if provided). +Default: empty Example: [display-posts include_excerpt="true"] -**include_title** -Include the post's title -Default: true +**include_title** +Include the post's title. +Default: true Example: [display-posts include_title="false" image_size="thumbnail"] **include_link** @@ -159,87 +164,87 @@ Post's title is link to post page. Default: true Example: [display-posts include_title="true" include_link="false"] -**meta_key** -Specify a meta key, for meta queries or ordering -Default: empty +**meta_key** +Specify a meta key, for meta queries or ordering. +Default: empty Example: [display-posts meta_key="price" orderby="meta_value_num" order="ASC"] -**meta_value** -Specify a meta value, for meta queries -Default: empty +**meta_value** +Specify a meta value, for meta queries. +Default: empty Example: [display-posts meta_key="color" meta_value="blue"] -**no_posts_message** -Specify a message to display if no posts are found -Default: empty +**no_posts_message** +Specify a message to display if no posts are found. +Default: empty Example: [display-posts category="on-sale" no_posts_message="Sorry, no items are currently on sale"] -**offset** -The number of posts to pass over -Default: 0 +**offset** +The number of posts to pass over. +Default: 0 Example: [display-posts offset="3"] -**order** -Specify whether posts are ordered in descending order (DESC) or ascending order (ASC). -Default: DESC +**order** +Specify whether posts are ordered in descending order (DESC) or ascending order (ASC). +Default: DESC Example: [display-posts order="ASC"] -**orderby** -Specify what the posts are ordered by. See the available parameters [here](http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters). -Default: date +**orderby** +Specify what the posts are ordered by. See the available parameters [here](http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters). +Default: date Example: [display-posts orderby="title"] -**post_parent** -Display the pages that are a child of a certain page. You can either specify an ID or 'current', which displays the children of the current page. -Default: empty +**post_parent** +Display the pages that are a child of a certain page. You can either specify an ID or 'current', which displays the children of the current page. +Default: empty Example: [display-posts post_type="page" post_parent="8"] -**post_status** -Show posts associated with a certain post status -Default: publish +**post_status** +Show posts associated with a certain post status. +Default: publish Example: [display-posts post_status="publish, future"] -**post_type** -Specify which post type to use. You can use a default one (post or page), or a custom post type you've created. -Default: post +**post_type** +Specify which post type to use. You can use a default one (post or page), or a custom post type you've created. +Default: post Example: [display-posts post_type="event"] -**posts_per_page** -How many posts to display. -Default: 10 +**posts_per_page** +How many posts to display. +Default: 10 Example: [display-posts posts_per_page="5"] -**tag** -Display posts from a specific tag, or tags. You must use the tag slug(ex: example-tag), not the tag's name (ex: Example Tag). -Default: empty +**tag** +Display posts from a specific tag, or tags. You must use the tag slug(ex: example-tag), not the tag's name (ex: Example Tag). +Default: empty Example: [display-posts tag="tag1, tag2"] -**taxonomy, tax_term, and tax_operator** -Use these parameters to do [advanced taxonomy queries](http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters). Use 'taxonomy' for the taxonomy you'd like to query, 'tax_term' for the term slug (or terms) you'd like to include, and 'operator' to change how the query uses those terms (most likely this field will not be needed). See [Multiple Taxonomy Queries](https://github.com/billerickson/display-posts-shortcode/wiki#multiple-taxonomy-queries) -Default: 'taxonomy' = empty , 'tax_term' = empty , 'tax_operator' = 'IN' +**taxonomy, tax_term, and tax_operator** +Use these parameters to do [advanced taxonomy queries](http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters). Use 'taxonomy' for the taxonomy you'd like to query, 'tax_term' for the term slug (or terms) you'd like to include, and 'operator' to change how the query uses those terms (most likely this field will not be needed). See [Multiple Taxonomy Queries](https://github.com/billerickson/display-posts-shortcode/wiki#multiple-taxonomy-queries). +Default: 'taxonomy' = empty , 'tax_term' = empty , 'tax_operator' = 'IN' Example: [display-posts taxonomy="color" tax_term="blue, green"] -**time** -Specify the time, to be used in a date query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries) -Default: empty +**time** +Specify the time, to be used in a date query. [More info on Date Queries](https://github.com/billerickson/display-posts-shortcode/wiki#date-queries). +Default: empty Example: [display-posts date="Yesterday" time="9:00am"] -**title** -Give the list of posts a title heading -Default: empty -Example: [display-posts title="Recent Posts"] +**title** +Give the list of posts a title heading. +Default: empty +Example: [display-posts title="Recent Posts"] -**wrapper** -What type of HTML should be used to display the listings. It can be an unordered list (ul), ordered list (ol), or divs (div) which you can then style yourself. -Default: ul +**wrapper** +What type of HTML should be used to display the listings. It can be an unordered list (ul), ordered list (ol), or divs (div) which you can then style yourself. +Default: ul Example: [display-posts wrapper="ol"] -**wrapper_class** -Class applied to the wrapper tag for custom css formatting for this instance. -Default: display-posts-listing +**wrapper_class** +Class applied to the wrapper tag for custom css formatting for this instance. +Default: display-posts-listing Example: [display-posts wrapper="div" wrapper_class="my-grid-layout"] -**wrapper_id** -Specify an unique ID to be used on the wrapper of this listing -Default: empty +**wrapper_id** +Specify an unique ID to be used on the wrapper of this listing. +Default: empty Example: [display-posts category="cars" wrapper_id="cars-listing"] diff --git a/display-posts-shortcode.php b/display-posts-shortcode.php index cc2dd59..66d4ed3 100644 --- a/display-posts-shortcode.php +++ b/display-posts-shortcode.php @@ -61,6 +61,7 @@ function be_display_posts_shortcode( $atts ) { 'include_author' => false, 'include_content' => false, 'include_date' => false, + 'include_date_modified'=> false, 'include_excerpt' => false, 'include_link' => true, 'include_title' => true, @@ -114,6 +115,7 @@ function be_display_posts_shortcode( $atts ) { $include_author = filter_var( $atts['include_author'], FILTER_VALIDATE_BOOLEAN ); $include_content = filter_var( $atts['include_content'], FILTER_VALIDATE_BOOLEAN ); $include_date = filter_var( $atts['include_date'], FILTER_VALIDATE_BOOLEAN ); + $include_date_modified= filter_var( $atts['include_date_modified'], FILTER_VALIDATE_BOOLEAN ); $include_excerpt = filter_var( $atts['include_excerpt'], FILTER_VALIDATE_BOOLEAN ); $include_link = filter_var( $atts['include_link'], FILTER_VALIDATE_BOOLEAN ); $meta_key = sanitize_text_field( $atts['meta_key'] ); @@ -408,9 +410,12 @@ function be_display_posts_shortcode( $atts ) { } - if ( $include_date ) + if ( $include_date ) { $date = ' ' . get_the_date( $date_format ) . ''; - + } elseif ( $include_date_modified ) { + $date = ' ' . get_the_modified_date( $date_format ) . ''; + } + if( $include_author ) /** * Filter the HTML markup to display author information for the current post.