Skip to content

Commit

Permalink
about latest-posts-for-elementor widget
Browse files Browse the repository at this point in the history
版本 1.1.0

功能增强:
1. 新增显示控制选项:
   - 可单独控制标题、日期、作者和缩略图的显示
2. 增加样式自定义功能:
   - 缩略图尺寸现在支持像素和百分比设置
   - 可自定义"NEWS"文字颜色
3. 新增广告(AD)帖子功能:
   - 可设置AD帖子显示位置
   - 支持循环显示AD帖子选项

样式优化:
1. 改进缩略图样式,支持responsive设计
2. 优化整体布局,提高可读性

代码改进:
1. 重构Latest_Posts_Widget类,提高代码可维护性
2. 优化CSS结构,增加AD帖子相关样式

其他改进:
1. 增加中文注释,提高代码可读性
2. 完善Elementor编辑器中的设置选项,提供更直观的用户体验

注意:此更新包含多项新功能和样式变更,建议用户更新后检查并调整现有页面中使用的Latest Posts小部件设置。
  • Loading branch information
amm10090 committed Aug 25, 2024
1 parent 1254e47 commit b50750f
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* 最新新闻小部件的整体样式 */
.latest-news-widget {
font-family: Arial, sans-serif;
}

/* 标题样式 */
.latest-news-title {
font-size: 24px;
font-weight: bold;
Expand All @@ -18,13 +20,15 @@
color: #0073aa;
}

/* 新闻项目样式 */
.news-item {
display: flex;
margin-bottom: 20px;
padding-bottom: 20px;
border-bottom: 1px solid #eee;
}

/* 缩略图样式 */
.news-thumbnail {
flex: 0 0 30%;
margin-right: 20px;
Expand All @@ -35,6 +39,7 @@
height: auto;
}

/* 新闻内容样式 */
.news-content {
flex: 1;
}
Expand All @@ -47,4 +52,19 @@
.news-meta {
font-size: 14px;
color: #666;
}

/* AD 帖子样式 */
.ad-post .news-thumbnail {
position: relative;
}

.ad-post .ad-label {
position: absolute;
top: 0;
right: 0;
background: rgba(0, 0, 0, 0.7);
color: white;
padding: 2px 5px;
font-size: 12px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Plugin Name: Latest Posts for Elementor
* Description: Adds a Latest Posts widget for Elementor page builder
* Plugin URI: https://github.com/amm10090/amo/releases/
* Version: 1.0.5
* Version: 1.1.0
* Author: HuaYangTian
* Author URI: https://blog.amoze.cc/
* Text Domain: latest-posts-for-elementor
Expand Down Expand Up @@ -35,7 +35,7 @@ final class Latest_Posts_For_Elementor {
*
* @var string The plugin version.
*/
const VERSION = '1.0.5';
const VERSION = '1.1.0';

/**
* Minimum Elementor Version
Expand Down
27 changes: 26 additions & 1 deletion amusementbreak/latest-posts-for-elementor/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: huayangtian
Tags: elementor, posts, widget, latest posts
Requires at least: 5.0
Tested up to: 6.2
Stable tag: 1.0.5
Stable tag: 1.1.0
Requires PHP: 7.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Expand Down Expand Up @@ -43,6 +43,31 @@ Yes, the widget provides various customization options. You can adjust the layou
= 1.0.0 =
* Initial release

= 1.1.0 =
功能增强:
1. 新增显示控制选项:
- 可单独控制标题、日期、作者和缩略图的显示
2. 增加样式自定义功能:
- 缩略图尺寸现在支持像素和百分比设置
- 可自定义"NEWS"文字颜色
3. 新增广告(AD)帖子功能:
- 可设置AD帖子显示位置
- 支持循环显示AD帖子选项

样式优化:
1. 改进缩略图样式,支持responsive设计
2. 优化整体布局,提高可读性

代码改进:
1. 重构Latest_Posts_Widget类,提高代码可维护性
2. 优化CSS结构,增加AD帖子相关样式

其他改进:
1. 增加中文注释,提高代码可读性
2. 完善Elementor编辑器中的设置选项,提供更直观的用户体验

注意:此更新包含多项新功能和样式变更,建议用户更新后检查并调整现有页面中使用的Latest Posts小部件设置。

== Upgrade Notice ==

= 1.0.0 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function get_keywords() {
}

protected function register_controls() {

// 内容设置
$this->start_controls_section(
'content_section',
[
Expand All @@ -47,6 +47,7 @@ protected function register_controls() {
]
);

// 文章数量设置
$this->add_control(
'posts_per_page',
[
Expand All @@ -59,8 +60,145 @@ protected function register_controls() {
]
);

// 显示控制
$this->add_control(
'show_title',
[
'label' => esc_html__('Show Title', 'latest-posts-for-elementor'),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
]
);

$this->add_control(
'show_date',
[
'label' => esc_html__('Show Date', 'latest-posts-for-elementor'),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
]
);

$this->add_control(
'show_author',
[
'label' => esc_html__('Show Author', 'latest-posts-for-elementor'),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
]
);

$this->add_control(
'show_thumbnail',
[
'label' => esc_html__('Show Thumbnail', 'latest-posts-for-elementor'),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
]
);

// AD 帖子设置
$this->add_control(
'ad_post_position',
[
'label' => esc_html__('AD Post Position', 'latest-posts-for-elementor'),
'type' => Controls_Manager::NUMBER,
'min' => 1,
'max' => 100,
'step' => 1,
'default' => 3,
]
);

$this->add_control(
'ad_post_repeat',
[
'label' => esc_html__('Repeat AD Post', 'latest-posts-for-elementor'),
'type' => Controls_Manager::SWITCHER,
'default' => 'no',
]
);

$this->end_controls_section();

// 样式设置
$this->start_controls_section(
'style_section',
[
'label' => esc_html__('Style', 'latest-posts-for-elementor'),
'tab' => Controls_Manager::TAB_STYLE,
]
);

// 缩略图宽度设置
$this->add_responsive_control(
'thumbnail_width',
[
'label' => esc_html__('Thumbnail Width', 'latest-posts-for-elementor'),
'type' => Controls_Manager::SLIDER,
'size_units' => ['px', '%'],
'range' => [
'px' => [
'min' => 0,
'max' => 1000,
'step' => 1,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'default' => [
'unit' => '%',
'size' => 30,
],
'selectors' => [
'{{WRAPPER}} .news-thumbnail' => 'width: {{SIZE}}{{UNIT}};',
],
]
);

// 缩略图高度设置
$this->add_responsive_control(
'thumbnail_height',
[
'label' => esc_html__('Thumbnail Height', 'latest-posts-for-elementor'),
'type' => Controls_Manager::SLIDER,
'size_units' => ['px', '%'],
'range' => [
'px' => [
'min' => 0,
'max' => 1000,
'step' => 1,
],
'%' => [
'min' => 0,
'max' => 100,
],
],
'default' => [
'unit' => 'px',
'size' => 200,
],
'selectors' => [
'{{WRAPPER}} .news-thumbnail img' => 'height: {{SIZE}}{{UNIT}}; object-fit: cover;',
],
]
);

// "NEWS" 颜色设置
$this->add_control(
'news_color',
[
'label' => esc_html__('News Color', 'latest-posts-for-elementor'),
'type' => Controls_Manager::COLOR,
'selectors' => [
'{{WRAPPER}} .latest-news-title .news' => 'color: {{VALUE}}',
],
]
);

$this->end_controls_section();
}

protected function render() {
Expand All @@ -80,16 +218,36 @@ protected function render() {
echo '<div class="latest-news-widget">';
echo '<h2 class="latest-news-title"><span class="latest">Latest</span> <span class="news">News</span></h2>';
echo '<div class="news-container">';
$post_count = 0;
while ( $latest_posts->have_posts() ) : $latest_posts->the_post();
$post_count++;

// 检查是否应该插入 AD 帖子
if ($post_count == $settings['ad_post_position'] ||
($settings['ad_post_repeat'] === 'yes' && $post_count % $settings['ad_post_position'] === 0)) {
$this->render_ad_post();
}

echo '<div class="news-item">';
if ( has_post_thumbnail() ) {
if ( $settings['show_thumbnail'] === 'yes' && has_post_thumbnail() ) {
echo '<div class="news-thumbnail">';
the_post_thumbnail( 'thumbnail' );
echo '</div>';
}
echo '<div class="news-content">';
echo '<h3 class="news-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>';
echo '<div class="news-meta">' . get_the_date() . ' | ' . get_the_author() . '</div>';
if ( $settings['show_title'] === 'yes' ) {
echo '<h3 class="news-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>';
}
if ( $settings['show_date'] === 'yes' || $settings['show_author'] === 'yes' ) {
echo '<div class="news-meta">';
if ( $settings['show_date'] === 'yes' ) {
echo get_the_date() . ' ';
}
if ( $settings['show_author'] === 'yes' ) {
echo '| ' . get_the_author();
}
echo '</div>';
}
echo '</div>';
echo '</div>';
endwhile;
Expand All @@ -102,4 +260,17 @@ protected function render() {
wp_reset_postdata();
}

// 渲染 AD 帖子
protected function render_ad_post() {
echo '<div class="news-item ad-post">';
echo '<div class="news-thumbnail">';
echo '<img src="' . plugins_url( 'assets/images/ad-placeholder.jpg', __FILE__ ) . '" alt="AD">';
echo '<span class="ad-label">AD</span>';
echo '</div>';
echo '<div class="news-content">';
echo '<h3 class="news-title"><a href="#">Advertisement Title</a></h3>';
echo '<div class="news-meta">Sponsored Content</div>';
echo '</div>';
echo '</div>';
}
}

0 comments on commit b50750f

Please sign in to comment.