Skip to content

Commit ebf1c30

Browse files
committed
Update Latest-Posts-Hover.php
1 parent a3f0a36 commit ebf1c30

1 file changed

Lines changed: 53 additions & 103 deletions

File tree

widgets/Latest-Posts-Hover.php

Lines changed: 53 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ protected function _register_controls()
206206
'type' => \Elementor\Controls_Manager::SWITCHER,
207207
'label_on' => esc_html__('On', 'Latest-Posts-Hover'),
208208
'label_off' => esc_html__('Off', 'Latest-Posts-Hover'),
209-
'return_value' => 'block',
209+
'return_value' => 'inline-block',
210210
'default' => 'none',
211211
'selectors' => [
212212
'{{WRAPPER}} .date' => 'display: {{VALUE}};',
@@ -507,7 +507,6 @@ protected function _register_controls()
507507
'default' => 'left',
508508
'toggle' => true,
509509
'selectors' => [
510-
'{{WRAPPER}} .categories-links' => 'text-align: {{VALUE}};',
511510
'{{WRAPPER}} .category' => 'text-align: {{VALUE}};',
512511

513512

@@ -689,7 +688,7 @@ protected function _register_controls()
689688
[
690689
'label' => esc_html__('Inactive text color', 'Latest-Posts-Hover'),
691690
'type' => \Elementor\Controls_Manager::COLOR,
692-
'default' => 'black',
691+
'default' => 'white',
693692
'selectors' => [
694693
'{{WRAPPER}} .category-filter-button' => ' color: {{VALUE}} !important;',
695694
],
@@ -756,7 +755,7 @@ protected function _register_controls()
756755
[
757756
'label' => esc_html__('Active text clor', 'Latest-Posts-Hover'),
758757
'type' => \Elementor\Controls_Manager::COLOR,
759-
'default' => 'black',
758+
'default' => 'white',
760759
'selectors' => [
761760
'{{WRAPPER}} .category-filter-button.active' => ' color: {{VALUE}} !important;',
762761
],
@@ -778,7 +777,7 @@ protected function _register_controls()
778777
[
779778
'label' => esc_html__('Active background color', 'Latest-Posts-Hover'),
780779
'type' => \Elementor\Controls_Manager::COLOR,
781-
'default' => 'black',
780+
'default' => 'red',
782781
'selectors' => [
783782
'{{WRAPPER}} .category-filter-button.active' => ' background-color: {{VALUE}};',
784783
],
@@ -823,7 +822,7 @@ protected function _register_controls()
823822
[
824823
'label' => esc_html__('Hover text color', 'Latest-Posts-Hover'),
825824
'type' => \Elementor\Controls_Manager::COLOR,
826-
'default' => 'black',
825+
'default' => 'white',
827826
'selectors' => [
828827
'{{WRAPPER}} .category-filter-button:hover' => ' color: {{VALUE}} !important;',
829828
],
@@ -845,7 +844,7 @@ protected function _register_controls()
845844
[
846845
'label' => esc_html__('Hover background color', 'Latest-Posts-Hover'),
847846
'type' => \Elementor\Controls_Manager::COLOR,
848-
'default' => 'black',
847+
'default' => 'orange',
849848
'selectors' => [
850849
'{{WRAPPER}} .category-filter-button:hover' => ' background-color: {{VALUE}};',
851850
],
@@ -910,25 +909,18 @@ protected function render()
910909
$args = [
911910
'posts_per_page' => $settings['posts_per_page'],
912911
'category_name' => isset($_GET['category']) ? sanitize_text_field($_GET['category']) : '',
912+
'tag' => isset($_GET['tags']) ? sanitize_text_field($_GET['tags']) : '',
913913
];
914914
if (isset($_GET['category']) && ($_GET['category']) == "all") {
915915
$args = [
916916
'posts_per_page' => $settings['posts_per_page'],
917917
];
918918
}
919-
if(isset($_GET['category']) && (!$_GET['category']) == "all") {
920-
$args = [
921-
'posts_per_page' => $settings['posts_per_page'],
922-
'category_name' => isset($_GET['category']) ? sanitize_text_field($_GET['category']) : '',
923-
924-
];
925-
}
926919
if ($settings['all_post'] == 'all') {
927920
$args = [
928921
'posts_per_page' => -1,
929922
];
930923
}
931-
932924
$posts = get_posts($args);
933925
$cardColor = $settings['card_color'];
934926
$wordPc = $settings['content_word_pc'];
@@ -940,11 +932,10 @@ protected function render()
940932
$flex = 25;
941933
}
942934
$widht = $flex - 1;
943-
$title_color = $settings['Title_color'];
944-
if ($posts) {
935+
if ($posts) {
945936
echo '<div class="category-filter">
946-
<form method="get" action="">
947-
<button type="submit" name="category" value="all" class="category-filter-button';
937+
<form method="get" action="">
938+
<button type="submit" name="category" value="all" class="category-filter-button';
948939
if (isset($_GET['category']) && $_GET['category'] == 'all') {
949940
echo ' active';
950941
}
@@ -962,73 +953,14 @@ protected function render()
962953
echo '</form> </div>';
963954
echo '<div class="card2-container">';
964955
$selected_page_id = $settings['selected_page'];
965-
if (wp_is_mobile()) {
966-
// Codice da eseguire se la larghezza dello schermo è minore o uguale a 900 pixel
967-
968-
// Rendering dei post
969-
foreach ($posts as $post) {
970-
$post_title = get_the_title($post->ID);
971-
$post_content = wp_trim_words($post->post_content, $wordPc);
972-
$post_date = date_i18n(get_option('date_format'), strtotime($post->post_date));
973-
$post_link = get_permalink($post->ID);
974-
$tags = get_the_tags($post->ID);
975-
if ($tags) {
976-
foreach ($tags as $tag) {
977-
echo '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>';
978-
}
979-
// Check if the post has a featured image
980-
$featured_image = get_the_post_thumbnail_url($post->ID);
981-
if (!$featured_image) {
982-
// If not, use the custom default image
983-
$featured_image = $settings['default_image']['url'];
984-
}
985-
echo '<div class="card2" style="background-image: url(' . $featured_image . '); ">';
986-
echo '
987-
<div class="info">
988-
<a class="title" href="' . $post_link . '">' . $post_title . ' <a/>';
989-
if ($tags) {
990-
echo '<div class="categories-links">';
991-
foreach ($tags as $tag) {
992-
echo '<a href="' . get_tag_link($tag->term_id) . '" class="tag">' . $tag->name . '</a> ';
993-
} echo '</div>';
994-
} echo'
995-
<p class="date">' . $post_date . '</p> ';
996-
if ($selected_page_id != 0) {
997-
$page_link = get_permalink($selected_page_id);
998-
$categories = get_the_category($post->ID);
999-
if (!empty($categories)) {
1000-
echo '<div class="categories-links">';
1001-
foreach ($categories as $category) {
1002-
$category_link = add_query_arg('category', $category->slug, $page_link);
1003-
echo '<a href="' . $category_link . '" class="category"> ' . $category->name . '&nbsp; </a>';
1004-
}
1005-
echo '</div>';
1006-
}
1007-
} else {
1008-
$categories = get_the_category($post->ID);
1009-
if (!empty($categories)) {
1010-
echo '<div class="categories-links">';
1011-
foreach ($categories as $category) {
1012-
echo '<a href="' . get_category_link($category->term_id) . '" class="category"> ' . $category->name . '&nbsp; </a>';
1013-
}
1014-
echo '</div>';
1015-
}
1016-
}
1017-
echo '<a class="description" href="' . $post_link . '">' . $post_content . ' </a>
1018-
</div>
1019-
</div>';
1020-
}
1021-
wp_reset_postdata();
1022-
echo '</div>';
1023-
}
1024-
}
1025-
else {
1026-
foreach ($posts as $post) {
956+
957+
foreach ($posts as $post) {
1027958
$post_title = get_the_title($post->ID);
1028959
$post_content = wp_trim_words($post->post_content, $wordPc);
1029-
$post_date = date_i18n(get_option('date_format'), strtotime($post->post_date));
960+
$post_date = get_the_date('j F Y', $post->ID);
1030961
$post_link = get_permalink($post->ID);
1031962
$tags = get_the_tags($post->ID);
963+
$tags_active=$settings['tag_active'];
1032964
// Check if the post has a featured image
1033965
$featured_image = get_the_post_thumbnail_url($post->ID);
1034966
if (!$featured_image) {
@@ -1038,49 +970,67 @@ protected function render()
1038970
if (is_admin()) {
1039971
echo '<div class="card2" style="background-image: url(' . $featured_image . '); ">';
1040972
} else {
1041-
echo ' <div class="card2" style="background-image: url(' . $featured_image . '); "onclick=\'window.location.href="' . $post_link . '"\'>';
973+
echo ' <div class="card2" style="background-image: url(' . $featured_image . '); ';if (!wp_is_mobile()){echo'onclick=\'window.location.href="' . $post_link . '"\'>';}
974+
else{echo'">';}
1042975
}
1043976
echo '
1044-
<div class="info">
1045-
<a class="title" href="' . $post_link . '">' . $post_title . ' <a/>';
1046-
if ($tags) {
1047-
echo '<div class="categories-links">';
977+
<div class="info">
978+
<a class="title" href="' . $post_link . '">' . $post_title . ' <a/>';
979+
if (!empty($tags)) {
980+
if ($selected_page_id != 0) {
981+
$page_link = get_permalink($selected_page_id);
982+
foreach ($tags as $tag) {
983+
$tag_link = add_query_arg('tags', $tag->slug, $page_link);
984+
echo '<a href="' . $tag_link . '" class="tag"> ' . $tag->name . '</a> ';
985+
} }
986+
else{
1048987
foreach ($tags as $tag) {
1049-
echo '<a href="' . get_tag_link($tag->term_id) . '" class="tag">' . $tag->name . '</a>';
988+
echo '<a href="' . get_tag_link($tag->term_id) . '" class="tag">' . $tag->name . '</a> ';
989+
} }
990+
}
991+
$date_parts = explode(' ', $post_date);
992+
if ($selected_page_id != 0) {
993+
$page_link = get_permalink($selected_page_id);
994+
foreach ($date_parts as $part) {
995+
$date_link = add_query_arg('date', $post_date, $page_link);
996+
997+
echo ' <div><a href="' . $date_link . '" class="date"><p>' . ucfirst($part) . '</a></div>';
998+
}
999+
} else {
1000+
echo '<div>';
1001+
foreach ($date_parts as $part) {
1002+
$date_link = get_day_link($post->post_year, $post->post_month, $post->post_day, $post->ID);
1003+
echo '<a href="' . $date_link . '" class="date">' . ucfirst($part) . '</a>';
10501004

1051-
}
1052-
echo '</div>';
1053-
}
1054-
echo'<p class="date">' . $post_date . '</p> ';
1055-
if ($selected_page_id != 0) {
1005+
} echo '</div>';
1006+
1007+
1008+
}
1009+
if ($selected_page_id != 0) {
10561010
$page_link = get_permalink($selected_page_id);
10571011
$categories = get_the_category($post->ID);
10581012
if (!empty($categories)) {
1059-
echo '<div class="categories-links">';
10601013
foreach ($categories as $category) {
10611014
$category_link = add_query_arg('category', $category->slug, $page_link);
1062-
echo '<a href="' . $category_link . '" class="category"> ' . $category->name . '<br>; </a>';
1015+
echo '<a href="' . $category_link . '" class="category"> ' . $category->name . ' </a>';
10631016
}
1064-
echo '</div>';
10651017
}
10661018
} else {
10671019
$categories = get_the_category($post->ID);
10681020
if (!empty($categories)) {
1069-
echo '<div class="categories-links">';
10701021
foreach ($categories as $category) {
1071-
echo '<a href="' . get_category_link($category->term_id) . '" class="category"> ' . $category->name . '&nbsp; </a>';
1022+
echo '<a href="' . get_category_link($category->term_id) . '" class="category"> ' . $category->name . ' </a>';
10721023
}
1073-
echo '</div>';
10741024
}
10751025
}
10761026
echo '<a class="description" href="' . $post_link . '">' . $post_content . ' </a>
1077-
</div>
1078-
</div>';
1027+
</div>
1028+
</div>';
10791029
}
10801030
wp_reset_postdata();
10811031
echo '</div>';
10821032
}
1083-
} else {
1033+
if(!$posts) {
10841034
// Gestisci il caso in cui $posts non è un array valido
10851035
echo '<div class="error-message">';
10861036
echo esc_html__('No post', 'Latest-Posts-Hover');
@@ -1194,7 +1144,7 @@ protected function render()
11941144
font-size: 18px;
11951145
color:black;
11961146
display:none;
1197-
text-align: center;
1147+
text-align: left;
11981148
}
11991149
.date {
12001150
margin-top: 0;

0 commit comments

Comments
 (0)