From 3ad3fd8fbfb791ee7cc4b1eb9e689bc15b596a5c Mon Sep 17 00:00:00 2001 From: Stephen Cameron Date: Thu, 19 Dec 2019 19:09:02 +0100 Subject: [PATCH] WIP #3053 --- .../mu-plugins/cube/src/Elementor/Setup.php | 1 + .../src/Elementor/Widgets/ScientificNews.php | 105 ++++++++++++++++++ .../content-scientific_news.blade.php | 23 ++-- .../content-single-scientific_news.blade.php | 2 +- 4 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 wp-content/mu-plugins/cube/src/Elementor/Widgets/ScientificNews.php diff --git a/wp-content/mu-plugins/cube/src/Elementor/Setup.php b/wp-content/mu-plugins/cube/src/Elementor/Setup.php index 556b0f6..b52c12f 100644 --- a/wp-content/mu-plugins/cube/src/Elementor/Setup.php +++ b/wp-content/mu-plugins/cube/src/Elementor/Setup.php @@ -40,6 +40,7 @@ class Setup { $elementor->widgets_manager->register_widget_type( new Widgets\PhotoGrid() ); $elementor->widgets_manager->register_widget_type( new Widgets\PeopleGrid() ); $elementor->widgets_manager->register_widget_type( new Widgets\Timeline() ); + $elementor->widgets_manager->register_widget_type( new Widgets\ScientificNews() ); } protected function _customise_sections() { diff --git a/wp-content/mu-plugins/cube/src/Elementor/Widgets/ScientificNews.php b/wp-content/mu-plugins/cube/src/Elementor/Widgets/ScientificNews.php new file mode 100644 index 0000000..0184156 --- /dev/null +++ b/wp-content/mu-plugins/cube/src/Elementor/Widgets/ScientificNews.php @@ -0,0 +1,105 @@ +start_controls_section( + 'section_content', + [ + 'label' => __( 'Scientific News Posts', 'cube' ), + ] + ); + + $this->add_control( + 'widget_description', + [ + 'raw' => __( 'This widget will display the most recent scientific news posts.', 'cube' ), + 'type' => Controls_Manager::RAW_HTML, + 'content_classes' => 'elementor-descriptor', + ] + ); + + $this->add_control( + 'posts_limit', + [ + 'label' => __( 'Number of posts to display', 'cube' ), + 'type' => Controls_Manager::NUMBER, + 'default' => 10, + ] + ); + + $this->end_controls_section(); + + $this->common_controls(); + } + /** + * Render the widget output on the frontend. + * Written in PHP and used to generate the final HTML. + * + * @since 1.0.0 + * @access protected + */ + protected function render() { + + $posts_limit = $this->get_settings('posts_limit'); + + $science_posts = wp_get_recent_posts([ + 'numberposts' => $posts_limit, + 'orderby' => 'post_date', + 'order' => 'DESC', + 'post_type' => 'scientific_news', + 'post_status' => 'publish', + 'suppress_filters' => true + ]); + + if ($science_posts) { + foreach ($science_posts as $science_post) { + echo view('partials.content-scientific_news', compact('science_post')); + } + } + + } +} diff --git a/wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php b/wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php index b18c050..8731dee 100644 --- a/wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php +++ b/wp-content/themes/CCV/resources/views/partials/content-scientific_news.blade.php @@ -1,24 +1,33 @@ -
+@php + // Note: since this template is used by the standard WordPress loop AND by the Elementor widget, which + // exists outside the loop, we are sometimes getting data that is passed in and other times relying on + // the global loop context. As a result, the code had to be modified a bit to work in both situations. + $postID = isset($science_post) ? $science_post['ID'] : $post->ID; +@endphp -
- +
> + +
+
{{-- Just here as a proportional sizer thanks to the padding --}}

- - {!! $title !!} + + {!! get_the_title($postID) !!}

- @php(the_excerpt()) + @php + echo apply_filters( 'the_excerpt', get_the_excerpt($postID)); + @endphp

- + @svg('arrow', 'h-3 mr-2 fill-current') diff --git a/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php b/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php index eb14500..b2a20b5 100644 --- a/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php +++ b/wp-content/themes/CCV/resources/views/partials/content-single-scientific_news.blade.php @@ -29,7 +29,7 @@ @php(the_content())

- + @svg('arrow', 'h-3 mr-2 fill-current') -- 2.39.5