From 8441fc4555948d6adb16c9846856883c651ade6e Mon Sep 17 00:00:00 2001 From: 3Dblog maker Date: Tue, 8 Dec 2020 18:15:24 +0200 Subject: [PATCH 1/2] Create excerpt.php A little bit a monkeying around, there was no {@excerpt/} like there were {@content/} So I figure out to make new copy_paste from the content helper and just change every instance of a the_content()-function on to a the_excerpt()-function and make some fiddling and then name it new file to a excerpt, thus I made that {@excerpt/} works. --- helpers/excerpt.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 helpers/excerpt.php diff --git a/helpers/excerpt.php b/helpers/excerpt.php new file mode 100644 index 00000000..516e7366 --- /dev/null +++ b/helpers/excerpt.php @@ -0,0 +1,23 @@ +namespace DustPress; + +class Excerpt extends Helper { + public function output() { + global $post; + + if ( isset( $this->params->data ) ) { + return apply_filters( 'the_excerpt', $this->params->data ); + } else { + if ( isset( $this->params->id ) ) { + $post = get_post( $this->params->id ); + } + + ob_start(); + setup_postdata( $post ); + the_excerpt(); + wp_reset_postdata(); + return ob_get_clean(); + } + } +} + +$this->add_helper( 'excerpt', new Excerpt() ); From 00b6950cc0c40d43df3a6ee2efb03d611f3f16d3 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Mon, 29 Mar 2021 09:32:28 +0300 Subject: [PATCH 2/2] Apply suggestions from code review --- helpers/excerpt.php | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/helpers/excerpt.php b/helpers/excerpt.php index 516e7366..7ee71865 100644 --- a/helpers/excerpt.php +++ b/helpers/excerpt.php @@ -1,3 +1,4 @@ +params->data ) ) { return apply_filters( 'the_excerpt', $this->params->data ); - } else { - if ( isset( $this->params->id ) ) { - $post = get_post( $this->params->id ); - } - - ob_start(); - setup_postdata( $post ); - the_excerpt(); - wp_reset_postdata(); - return ob_get_clean(); } + + if ( isset( $this->params->id ) ) { + $post = get_post( $this->params->id ); + } + + ob_start(); + setup_postdata( $post ); + the_excerpt(); + wp_reset_postdata(); + return ob_get_clean(); } }