Skip to content

Commit 0da1dba

Browse files
committed
Update Latest-Posts-Hover.php
1 parent fcd6c2d commit 0da1dba

1 file changed

Lines changed: 90 additions & 35 deletions

File tree

widgets/Latest-Posts-Hover.php

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
12
<?php
23
class Latest_Posts_Hover_Widget extends \Elementor\Widget_Base
34
{
@@ -663,10 +664,10 @@ protected function _register_controls()
663664
'type' => \Elementor\Controls_Manager::SWITCHER,
664665
'label_on' => esc_html__('On', 'Latest-Posts-Hover'),
665666
'label_off' => esc_html__('Off', 'Latest-Posts-Hover'),
666-
'return_value' => 'flex',
667+
'return_value' => 'inline-block',
667668
'default' => 'none',
668669
'selectors' => [
669-
'{{WRAPPER}} .category-filter' => 'display: {{VALUE}};',
670+
'{{WRAPPER}} .category-filter-button' => 'display: {{VALUE}};',
670671
],
671672
]
672673
);
@@ -910,13 +911,24 @@ protected function _register_controls()
910911
'type' => \Elementor\Controls_Manager::SWITCHER,
911912
'label_on' => esc_html__('On', 'Latest-Posts-Hover'),
912913
'label_off' => esc_html__('Off', 'Latest-Posts-Hover'),
913-
'return_value' => 'flex',
914+
'return_value' => 'inline-block',
914915
'default' => 'none',
915916
'selectors' => [
916917
'{{WRAPPER}} .container2' => 'display: {{VALUE}};',
917918
],
918919
]
919920
);
921+
$this->add_control(
922+
'related_category',
923+
[
924+
'label' => esc_html__('Show categories related to the one one you selected', 'Latest-Posts-Hover'),
925+
'type' => \Elementor\Controls_Manager::SWITCHER,
926+
'label_on' => esc_html__('On', 'Latest-Posts-Hover'),
927+
'label_off' => esc_html__('Off', 'Latest-Posts-Hover'),
928+
'return_value' => 'on',
929+
'default' => 'off',
930+
]
931+
);
920932
$this->end_controls_section();
921933
}
922934
private function get_category()
@@ -980,6 +992,7 @@ protected function render()
980992
if ($posts) {
981993
echo '<div class="category-filter">
982994
<form method="get" action="">';
995+
if($settings['related_category']!='on' || $settings['related_category']=='on'&& $settings['categories_in']==null){
983996
$args_C ['taxonomy']= 'category';
984997
$args_C['hide_empty'] = true;
985998
$args_C['exclude']= $settings['exclude_categories'];
@@ -991,9 +1004,9 @@ protected function render()
9911004
}
9921005
echo '">All</button>';
9931006

994-
}
995-
9961007

1008+
}
1009+
9971010
$categories = get_terms($args_C);
9981011
foreach ($categories as $category) {
9991012
$category_name = $category->name;
@@ -1004,11 +1017,32 @@ protected function render()
10041017
}
10051018
echo '">' . $category_name . '</button>';
10061019
}
1007-
if(!$args_C['include'] == null || !$args_C['exclude'] == null){
1008-
1009-
}
1010-
echo '</form> <div class="container2">
1011-
<div class="search">
1020+
}
1021+
if($settings['related_category']=='on' && $settings['categories_in']!=null){
1022+
$other_category_id = $settings['categories_in'];
1023+
$categories_with_posts = get_categories(array(
1024+
'hide_empty' => 0,
1025+
'child_of' => 0,
1026+
));
1027+
foreach ($categories_with_posts as $category) {
1028+
$posts_in_category = get_posts(array(
1029+
'category' => $category->term_id,
1030+
'category__in' => $other_category_id,
1031+
'posts_per_page' => 1,
1032+
));
1033+
1034+
if ($posts_in_category) {
1035+
$category_name = $category->name;
1036+
$category_slug = $category->slug;
1037+
echo '<button type="submit" name="category" value="' . $category_slug . '" class="category-filter-button';
1038+
if (isset($_GET['category']) && $_GET['category'] == $category_slug) {
1039+
echo ' active';
1040+
}
1041+
echo '">' . $category_name . '</button>';
1042+
} }
1043+
}
1044+
echo '</form> <div class="container2">
1045+
<div class="search">
10121046
<input type="text" placeholder="Search...">
10131047
<button type="submit"><i class="fa fa-search"></i></button>
10141048
</div>
@@ -1109,7 +1143,6 @@ protected function render()
11091143
}
11101144
wp_reset_postdata();
11111145
echo '</div>';
1112-
}
11131146
if (!$posts) {
11141147
// Gestisci il caso in cui $posts non è un array valido
11151148
echo '<div class="error-message">';
@@ -1120,24 +1153,33 @@ protected function render()
11201153
echo 'prova';
11211154
}
11221155
echo '<style>
1123-
* {
1124-
box-sizing: border-box;
1125-
outline: 0;
1126-
font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
1127-
}
1128-
11291156
.container2 {
1130-
width: 400px;
1157+
width: 394px;
11311158
height: 50px;
1132-
margin-bottom: 5px;
1133-
display: none;
1159+
display: none;
1160+
justify-content: end;';
1161+
if(!wp_is_mobile()){
1162+
echo'margin-top: 9px;';
1163+
echo'margin-bottom: 5px;';
1164+
1165+
}
1166+
else{
1167+
echo'margin-bottom: 5px;';
1168+
echo'margin-right: 19px;';
1169+
}
1170+
echo'
11341171
}
11351172
.container2 .search {
11361173
position: relative;
11371174
height: 100%;
1138-
1175+
pointer-events: stroke;
11391176
}
1140-
.container2 .search input {
1177+
.container2 input[type="text"]:focus {
1178+
caret-color: white;
1179+
1180+
}
1181+
1182+
.search input {
11411183
width: 50px;
11421184
height: 50px;
11431185
position: absolute;
@@ -1149,43 +1191,54 @@ protected function render()
11491191
color: #4e4e4e;
11501192
font-size: 18px;
11511193
font-weight: 300;
1152-
box-shadow: 0 5px 12px 0 rgba(0, 0, 0, 0.1),
1153-
0 1px 28px 0 rgba(0, 0, 0, 0.2),
1154-
0 0 40px 0 rgba(0, 0, 0, 0.1);
1194+
box-shadow: none;
11551195
transition: all 0.6s cubic-bezier(0, 2, 1, -1);
1196+
margin: 5;
11561197
}
1157-
.container2 .search button {
1198+
.search button {
11581199
width: 50px;
11591200
height: 50px;
11601201
position: absolute;
1161-
right: calc(50% - 25px);
1202+
right: calc(50% - 35px);
11621203
top: 0;
1163-
margin: auto;
1204+
margin: 5;
11641205
background: #2d2926;
11651206
color: #fff;
11661207
font-size: 15px;
11671208
border: 0;
11681209
border-radius: 50%;
1169-
box-shadow: 0 6px 28px 0 rgba(0, 0, 0, 0.0), 0 5px 55px 0 rgba(0, 0, 0, 0.0);
11701210
cursor: pointer;
1171-
transition:all 0.6s cubic-bezier(0, 2, 1, -1);
1211+
transition:all 0.6s cubic-bezier(0, 2, 1, -1);
11721212
}
1213+
.search input:focus {
1214+
right: 0;
1215+
border: 2px solid #007BFF; /* Add a colored border when in focus */
1216+
background-color: #f0f0f0; /* Change the background color when in focus */
11731217
1218+
}
11741219
.container2 .search input:focus,
11751220
.container2 .search input:active,
1176-
.container2 .search:hover input {
1177-
width: 400px;
1178-
right:0;
1221+
.container2 .search:hover input {';
1222+
if(wp_is_mobile()){
1223+
echo' width: 300px;';
1224+
1225+
}
1226+
else{
1227+
echo' width: 400px;';
1228+
1229+
}
1230+
echo'
1231+
right:0%;
1232+
background:red;
11791233
}
11801234
.container2 .search input:focus + button,
11811235
.container2 .search input:active + button,
11821236
.container2 .search:hover button {
11831237
right: 0;
1184-
box-shadow: 0 6px 28px 0 rgba(0, 0, 0, 0.3), 0 5px 55px 0 rgba(0, 0, 0, 0.2);
11851238
}
11861239
11871240
.category-filter {
1188-
display: none;
1241+
display: flex;
11891242
justify-content:right;
11901243
flex-wrap: wrap;
11911244
}
@@ -1204,6 +1257,7 @@ protected function render()
12041257
font-weight: normal;
12051258
font-family:Work Sans;
12061259
font: size 15px;
1260+
display:none;
12071261
}
12081262
12091263
.category-filter-button:hover {
@@ -1352,4 +1406,5 @@ protected function render()
13521406
13531407
</style>';
13541408
}
1409+
}
13551410
}

0 commit comments

Comments
 (0)