namespace PhysioAssist\Elementor\Widgets;
+use Elementor\Repeater;
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Scheme_Color;
]
);
+ $repeater = new Repeater();
+
+ $repeater->add_control(
+ 'category',
+ [
+ 'label' => __( 'Category', 'cube' ),
+ 'type' => Controls_Manager::SELECT,
+ 'options' => array_combine(array_column($this->getCats(), 'term_id'),array_column($this->getCats(), 'name'))
+ ]
+ );
+
+ $repeater->add_control(
+ 'post_date',
+ [
+ 'label' => esc_html__( 'Date', 'textdomain' ),
+ 'type' => Controls_Manager::DATE_TIME,
+ ]
+ );
+
+ $repeater->add_control(
+ 'post_title',
+ [
+ 'label' => __( 'Title', 'elementor' ),
+ 'type' => Controls_Manager::TEXT,
+ 'placeholder' => __( 'Enter your title', 'elementor' ),
+ 'default' => '',
+ ]
+ );
+
+ $repeater->add_control(
+ 'subtitle',
+ [
+ 'label' => __( 'Subtitle', 'cube' ),
+ 'type' => Controls_Manager::TEXTAREA,
+ 'label_block' => true,
+ ]
+ );
+
+ $repeater->add_control(
+ 'cta_text',
+ [
+ 'label' => __('Call to Action text', 'cube'),
+ 'type' => Controls_Manager::TEXT,
+ 'default' => ''
+ ]
+ );
+
+ $repeater->add_control(
+ 'cta_link',
+ [
+ 'label' => __('Call to Action link', 'cube'),
+ 'type' => Controls_Manager::URL,
+ 'default' => [
+ 'url' => '',
+ 'is_external' => false,
+ ],
+ 'show_external' => true
+ ]
+ );
+
+ $this->add_control(
+ 'items',
+ [
+ 'label' => __( 'Items', 'cube' ),
+ 'type' => Controls_Manager::REPEATER,
+ 'fields' => $repeater->get_controls(),
+ 'title_field' => '{{{ post_title }}}',
+ ]
+ );
+
$this->add_control(
'cta_text',
[
* @access protected
*/
protected function render() {
- $newsCat = get_category_by_slug('news');
- $categories = get_terms([
- 'taxonomy' => 'category',
- 'hide_empty' => false,
- 'exclude' => [$newsCat->term_id]
- ]);
- $categoriesId = array_map(function($n){ return $n->term_id; },$categories);
- $args = ['category__in'=>$categoriesId,'posts_per_page'=> -1];
- $items = get_posts($args);
+ $categories = $this->getCats();
$title = $this->get_settings('title');
+ $items = $this->get_settings('items');
$cta = [
'cta_text' => $this->get_settings('cta_text'),
echo template('widgets/flux-post-carousel', compact('items','categories', 'title', 'cta'));
}
+ public function getCats() {
+ $newsCat = get_category_by_slug('news');
+ return get_terms([
+ 'taxonomy' => 'category',
+ 'hide_empty' => false,
+ 'exclude' => [$newsCat->term_id]
+ ]);
+ }
+
+ public function getItems() {
+ return $this->get_settings('items');
+ }
+
}
\ No newline at end of file
* Do not edit anything in this file unless you know what you're doing
*/
+use Elementor\Plugin;
use Roots\Sage\Config;
use Roots\Sage\Container;
use function App\template;
+use PhysioAssist\Elementor\Widgets\FluxPostCarousel;
/**
* Helper function for prettying up errors
function flux_posts()
{
$catId = $_POST['cat'];
+ $widgetId = $_POST['widget_id'];
+ $sectionId = $_POST['section_id'];
- $newsCat = get_category_by_slug('news');
- $categories = get_terms([
- 'taxonomy' => 'category',
- 'hide_empty' => false,
- 'exclude' => [$newsCat->term_id]
- ]);
+ $widget_settings = get_post_meta(1406, '_elementor_data', true);
+ $widget_settings = json_decode($widget_settings,true);
- $categoriesId = array_map(function($n){ return $n->term_id; },$categories);
+ $items = array_filter($widget_settings, function($n) use($sectionId) { return $n['id'] === $sectionId; });
+ $items = array_values($items);
+ $items = $items[0]['elements'][0]['elements'][0]['settings']['items'];
+
+ if($catId) {
+ $items = array_filter($items, function($n) use($catId) { return $n['category'] === $catId; });
+ }
- $posts = get_posts([
- 'posts_per_page' => -1,
- 'category__in' => !empty($catId) ? [$catId] : $categoriesId,
- 'order' => 'desc'
- ]);
$current_language = apply_filters( 'wpml_current_language', NULL );
- foreach ($posts as $item) {
- $translated_id = apply_filters('wpml_object_id', $item->ID, 'post');
- $item = get_post($translated_id);
+ foreach ($items as $item) {
echo template('partials/post', compact('item'));
}
<div class="text-carousel-item flux-post-carousel-item slick-slide">
<div class="flux-post-carousel-item-content">
- <p class="flux-post-carousel-date">{!! date($format, strtotime($item->post_date)) !!}</p>
- <h3 class="flux-post-carousel-title">{{ $item->post_title }}</h3>
- <p class="flux-post-carousel-subtitle">{{ $item->subtitle }}</p>
- <a href="{{ get_the_permalink($item->ID) }}" class="arrow-link">@svg('arrow') {{ __('Read more', 'sage') }}</a>
+ @if (!empty($item['post_date']))
+ <p class="flux-post-carousel-date">{!! date($format, strtotime($item['post_date'])) !!}</p>
+ @endif
+ <h3 class="flux-post-carousel-title">{{ $item['post_title'] }}</h3>
+ <p class="flux-post-carousel-subtitle">{{ $item['subtitle'] }}</p>
+ @if (!empty($item['cta_text']))
+ <a href="{{ $item['cta_link']['url'] }}" class="arrow-link"
+ @if ($item['cta_link']['is_external']) target="_blank" @endif
+ @if ($item['cta_link']['nofollow']) rel="noopener" @endif
+ >
+ @svg('arrow') {{ $item['cta_text'] }}
+ </a>
+ @endif
</div> {{-- .flux-post-carousel-item-content --}}
</div> {{-- .flux-post-carousel-item --}}