Files
2024-11-20 09:09:44 +01:00

153 lines
4.5 KiB
PHP

<?php
namespace CE;
defined('_PS_VERSION_') or exit;
class WidgetSimpleBlog extends WidgetBase
{
use CarouselTrait;
public function getName()
{
return 'simple-blog';
}
public function getTitle()
{
return __('Simple Blog');
}
public function getIcon()
{
return 'eicon-post-list';
}
public function getKeywords()
{
return ['blog'];
}
protected function _registerControls()
{
$this->startControlsSection(
'section_text',
[
'label' => __('Treść'),
]
);
$this->addControl(
'header',
[
'label' => __('Nagłówek'),
'type' => ControlsManager::TEXT,
'default' => 'Simple Blog',
]
);
$this->endControlsSection();
// ---
$this->startControlsSection(
'section_style',
[
'label' => __('Text Editor'),
'tab' => ControlsManager::TAB_STYLE,
]
);
$this->addControl(
'post_data_color',
[
'label' => __('Article data color'),
'type' => ControlsManager::COLOR,
'selectors' => [
'{{WRAPPER}} .post-added' => 'color: {{VALUE}};',
],
]
);
$this->addGroupControl(
GroupControlTypography::getType(),
[
'label' => __('Article data czcionka'),
'name' => 'label_typography',
'selector' => '{{WRAPPER}} .post-added',
]
);
$this->endControlsSection();
}
/**
* Render video widget output on the frontend.
*
* Written in PHP and used to generate the final HTML.
*
* @since 1.0.0
*/
protected function render()
{
$settings = $this->getSettingsForDisplay();
?>
<div class="simple-blog-container">
<div class="simple-blog">
<h2><?php echo $settings['header']; ?></h2>
</div>
<div class="simple-blog-posts">
<?
// get last 3 posts from blog
// $sql = 'SELECT * FROM '._DB_PREFIX_.'xipposts WHERE active = 1 ORDER BY post_date DESC LIMIT 3';
$sql = '
SELECT p.*, l.*
FROM ' . _DB_PREFIX_ . 'ets_blog_post p
JOIN ' . _DB_PREFIX_ . 'ets_blog_post_lang l ON p.id_post = l.id_post
WHERE p.enabled = 1
ORDER BY p.date_add DESC
LIMIT 3
';
$results = \Db::getInstance()->executeS($sql);
if ( is_array( $results ) ) : ?>
<div class="swiper swiper-container" id="simple-blog-box">
<div class="swiper-wrapper">
<?php foreach ( $results as $row ): ?>
<div class="swiper-slide">
<div class="simple-blog-post">
<div class="_image">
<img src="/img/ets_blog/post/<?= $row['thumb']; ?>" alt="">
</div>
<div class="_content">
<!-- <p class="post-added"><?= date('F j, Y', strtotime($row['date_add'])); ?></p> -->
<a href="/blog/post/<?= $row['id_post']; ?>-<?= $row['url_alias']; ?>">
<h3 class="post-title"><?= $row['title']; ?></h3>
</a>
<!-- <div class="content-text">
<?php
if (strlen($row['short_description']) > 150) {
echo substr($row['short_description'], 0, 150) . '...';
} else {
echo $row['short_description'];
}
?>
</div> -->
<a href="/blog/post/<?= $row['id_post']; ?>-<?= $row['url_alias']; ?>" class="_btn">Czytaj więcej</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="elementor-swiper-button elementor-swiper-button-next">
<i class="ceicon-chevron-right" aria-hidden="true"></i>
</div>
<div class="elementor-swiper-button elementor-swiper-button-prev">
<i class="ceicon-chevron-left" aria-hidden="true"></i>
</div>
<?php endif; ?>
</div>
</div>
<?php
}
}