Skip to content

Commit 7b2a436

Browse files
committed
tag aggiunto
1 parent e355b26 commit 7b2a436

2 files changed

Lines changed: 141 additions & 7 deletions

File tree

Open-Elementor-Widget.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// Se il titolo è presente, restituisce solo il testo dopo di esso
2222
if ($position !== false) {
23-
$excerpt = preg_replace('#<a.*?>.*?</a>#i', '', $excerpt);
23+
$excerpt=preg_replace('#<a.*?>.*?</a>#i', '', $excerpt);
2424
return substr($excerpt, $position);
2525
}
2626
$excerpt = preg_replace('#<a.*?>.*?</a>#i', '', $excerpt);
@@ -50,4 +50,4 @@ function register_OpenElementorWidget_widgets($widgets_manager)
5050
// Include and register the latest-posts-hover widget
5151
require_once(plugin_dir_path(__FILE__) . 'widgets/Latest-Posts-Hover.php');
5252
$widgets_manager->register_widget_type(new \Latest_Posts_Hover_Widget());
53-
}
53+
}

widgets/Latest-Posts-Hover.php

Lines changed: 139 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ protected function _register_controls()
247247
$this->add_control(
248248
'date_font',
249249
[
250-
'label' => esc_html__('Font Family', 'Latest-Posts-Hover'),
250+
'label' => esc_html__('Font Date', 'Latest-Posts-Hover'),
251251
'type' => \Elementor\Controls_Manager::FONT,
252252
'default' => "Work Sans",
253253
'selectors' => [
@@ -301,6 +301,114 @@ protected function _register_controls()
301301
]
302302
);
303303
$this->end_controls_section();
304+
$this->start_controls_section(
305+
'section_tag',
306+
[
307+
'label' => esc_html__('Tag', 'Latest-Posts-Hover'),
308+
]
309+
);
310+
$this->add_control(
311+
'tag_active',
312+
[
313+
'label' => esc_html__('Tag Active', 'Latest-Posts-Hover'),
314+
'type' => \Elementor\Controls_Manager::SWITCHER,
315+
'label_on' => esc_html__('On', 'Latest-Posts-Hover'),
316+
'label_off' => esc_html__('Off', 'Latest-Posts-Hover'),
317+
'return_value' => 'block',
318+
'default' => 'none',
319+
'selectors' => [
320+
'{{WRAPPER}} .tag' => 'display: {{VALUE}};',
321+
],
322+
]
323+
);
324+
$this->add_control(
325+
'Tag_color',
326+
[
327+
'label' => esc_html__('Color Tag', 'Latest-Posts-Hover'),
328+
'type' => \Elementor\Controls_Manager::COLOR,
329+
'default' => 'black',
330+
'selectors' => [
331+
'{{WRAPPER}} .tag' => 'color: {{VALUE}};',
332+
],
333+
]
334+
);
335+
$this->add_control(
336+
'tag_font_size',
337+
[
338+
'label' => esc_html__('Size Tag', 'Latest-Posts-Hover'),
339+
'type' => \Elementor\Controls_Manager::SLIDER,
340+
'default' => [
341+
'size' => 18,
342+
'unit' => 'px',
343+
],
344+
'range' => [
345+
'px' => [
346+
'min' => 1,
347+
'max' => 120,
348+
],
349+
],
350+
'selectors' => [
351+
'{{WRAPPER}} .tag' => 'font-size: {{SIZE}}{{UNIT}};',
352+
],
353+
]
354+
);
355+
$this->add_control(
356+
'tag_font',
357+
[
358+
'label' => esc_html__('Font tag', 'Latest-Posts-Hover'),
359+
'type' => \Elementor\Controls_Manager::FONT,
360+
'default' => "Work Sans",
361+
'selectors' => [
362+
'{{WRAPPER}} .tag' => 'font-family: {{VALUE}}',
363+
],
364+
]
365+
);
366+
$this->add_control(
367+
'tag_bold',
368+
[
369+
'label' => esc_html__('Tag Bold', 'Latest-Posts-Hover'),
370+
'type' => \Elementor\Controls_Manager::SWITCHER,
371+
'label_on' => esc_html__('On', 'Latest-Posts-Hover'),
372+
'label_off' => esc_html__('Off', 'Latest-Posts-Hover'),
373+
'return_value' => 'bold',
374+
'default' => 'normal',
375+
'selectors' => [
376+
'{{WRAPPER}} .tag' => 'font-weight: {{VALUE}};',
377+
],
378+
]
379+
);
380+
$this->add_control(
381+
'tag_alignment',
382+
[
383+
'label' => esc_html__('Tag Alignment', 'OpenWidget'),
384+
'type' => \Elementor\Controls_Manager::CHOOSE,
385+
'options' => [
386+
'left' => [
387+
'title' => esc_html__('Left', 'OpenWidget'),
388+
'icon' => 'mce-ico mce-i-alignleft',
389+
],
390+
'center' => [
391+
'title' => esc_html__('Center', 'OpenWidget'),
392+
'icon' => 'mce-ico mce-i-aligncenter',
393+
],
394+
'right' => [
395+
'title' => esc_html__('Right', 'OpenWidget'),
396+
'icon' => 'mce-ico mce-i-alignright',
397+
],
398+
],
399+
'default' => 'left',
400+
'toggle' => true,
401+
'selectors' => [
402+
'{{WRAPPER}} .tag' => 'text-align: {{VALUE}};',
403+
],
404+
'icon_colors' => [
405+
'left' => 'white',
406+
'center' => 'white',
407+
'right' => 'white',
408+
],
409+
]
410+
);
411+
$this->end_controls_section();
304412
$this->start_controls_section(
305413
'section_category',
306414
[
@@ -862,6 +970,11 @@ protected function render()
862970
$post_content = wp_trim_words($post->post_content, $wordPc);
863971
$post_date = date_i18n(get_option('date_format'), strtotime($post->post_date));
864972
$post_link = get_permalink($post->ID);
973+
$tags = get_the_tags($post->ID);
974+
if ($tags) {
975+
foreach ($tags as $tag) {
976+
echo '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>';
977+
}
865978
// Check if the post has a featured image
866979
$featured_image = get_the_post_thumbnail_url($post->ID);
867980
if (!$featured_image) {
@@ -871,7 +984,11 @@ protected function render()
871984
echo '<div class="card2" style="background-image: url(' . $featured_image . '); ">';
872985
echo '
873986
<div class="info">
874-
<a class="title" href="' . $post_link . '">' . $post_title . ' <a/>
987+
<a class="title" href="' . $post_link . '">' . $post_title . ' <a/>';
988+
if ($tags) {
989+
foreach ($tags as $tag) {
990+
echo '<a href="' . get_tag_link($tag->term_id) . '" class="tag">' . $tag->name . '</a>';
991+
} } echo'
875992
<p class="date">' . $post_date . '</p> ';
876993
if ($selected_page_id != 0) {
877994
$page_link = get_permalink($selected_page_id);
@@ -900,12 +1017,15 @@ protected function render()
9001017
}
9011018
wp_reset_postdata();
9021019
echo '</div>';
903-
} else {
1020+
}
1021+
}
1022+
else {
9041023
foreach ($posts as $post) {
9051024
$post_title = get_the_title($post->ID);
9061025
$post_content = wp_trim_words($post->post_content, $wordPc);
9071026
$post_date = date_i18n(get_option('date_format'), strtotime($post->post_date));
9081027
$post_link = get_permalink($post->ID);
1028+
$tags = get_the_tags($post->ID);
9091029
// Check if the post has a featured image
9101030
$featured_image = get_the_post_thumbnail_url($post->ID);
9111031
if (!$featured_image) {
@@ -919,7 +1039,11 @@ protected function render()
9191039
}
9201040
echo '
9211041
<div class="info">
922-
<a class="title" href="' . $post_link . '">' . $post_title . ' <a/>
1042+
<a class="title" href="' . $post_link . '">' . $post_title . ' <a/>';
1043+
if ($tags) {
1044+
foreach ($tags as $tag) {
1045+
echo '<a href="' . get_tag_link($tag->term_id) . '" class="tag">' . $tag->name . '</a>';
1046+
} } echo'
9231047
<p class="date">' . $post_date . '</p> ';
9241048
if ($selected_page_id != 0) {
9251049
$page_link = get_permalink($selected_page_id);
@@ -952,7 +1076,7 @@ protected function render()
9521076
} else {
9531077
// Gestisci il caso in cui $posts non è un array valido
9541078
echo '<div class="error-message">';
955-
echo esc_html__('Impossibile recuperare i post. Si è verificato un errore.', 'Latest-Posts-Hover');
1079+
echo esc_html__('No post', 'Latest-Posts-Hover');
9561080
echo '</div>';
9571081
}
9581082
if (isset($_GET['action']) && $_GET['action'] === 'edit') {
@@ -1056,6 +1180,15 @@ protected function render()
10561180
text-align: center;
10571181
10581182
}
1183+
.tag {
1184+
margin-top: 0;
1185+
margin-bottom: 0px;
1186+
padding: 0 5px;
1187+
font-size: 18px;
1188+
color: black;
1189+
display:none;
1190+
text-align: left;
1191+
}
10591192
.date {
10601193
margin-top: 0;
10611194
margin-bottom: 0px;
@@ -1068,6 +1201,7 @@ protected function render()
10681201
.category {
10691202
margin-top: 0px;
10701203
margin-bottom: 0px;
1204+
padding: 0 5px;
10711205
font-size: 18px;
10721206
color:black;
10731207
display:none;

0 commit comments

Comments
 (0)