@@ -518,6 +518,24 @@ protected function _register_controls()
518518 ],
519519 ]
520520 );
521+ $ this ->add_control (
522+ 'categories_in ' ,
523+ [
524+ 'label ' => esc_html__ ('Select Categories to include ' , 'Latest-Posts-Hover ' ),
525+ 'type ' => \Elementor \Controls_Manager::SELECT2 ,
526+ 'multiple ' => true ,
527+ 'options ' => $ this ->get_category (),
528+ ]
529+ );
530+ $ this ->add_control (
531+ 'exclude_categories ' ,
532+ [
533+ 'label ' => esc_html__ ('Select Categories to exclude ' , 'Latest-Posts-Hover ' ),
534+ 'type ' => \Elementor \Controls_Manager::SELECT2 ,
535+ 'multiple ' => true ,
536+ 'options ' => $ this ->get_category (),
537+ ]
538+ );
521539 $ this ->end_controls_section ();
522540 $ this ->start_controls_section (
523541 'section_content ' ,
@@ -887,6 +905,15 @@ protected function _register_controls()
887905 );
888906
889907 $ this ->end_controls_section ();
908+ }
909+ private function get_category ()
910+ {
911+ $ categories = get_categories ();
912+ $ options = [];
913+ foreach ($ categories as $ category ) {
914+ $ options [$ category ->term_id ] = $ category ->name ;
915+ }
916+ return $ options ;
890917 }
891918 private function get_pages ()
892919 {
@@ -898,7 +925,7 @@ private function get_pages()
898925 }
899926 return $ options ;
900927 }
901-
928+
902929 protected function render ()
903930
904931 {
@@ -912,15 +939,21 @@ protected function render()
912939 'tag ' => isset ($ _GET ['tags ' ]) ? sanitize_text_field ($ _GET ['tags ' ]) : '' ,
913940 ];
914941 if (isset ($ _GET ['category ' ]) && ($ _GET ['category ' ]) == "all " ) {
915- $ args = [
916- 'posts_per_page ' => $ settings ['posts_per_page ' ],
917- ];
942+ unset($ args ['category_name ' ]);
918943 }
944+ if (isset ($ _GET ['date ' ])){
945+ $ date_query = [
946+ 'after ' => $ _GET ['date ' ],
947+ 'inclusive ' => true ,
948+ ];
949+ $ args ['date_query ' ] = $ date_query ;
950+ }
919951 if ($ settings ['all_post ' ] == 'all ' ) {
920- $ args = [
921- 'posts_per_page ' => -1 ,
922- ];
952+ $ args ['posts_per_page ' ] = -1 ;
923953 }
954+ $ args ['category__not_in ' ]=$ settings [ 'exclude_categories ' ];
955+ $ args ['category__in ' ]=$ settings [ 'categories_in ' ];
956+ $ args ['s ' ]='2024 ' ;
924957 $ posts = get_posts ($ args );
925958 $ cardColor = $ settings ['card_color ' ];
926959 $ wordPc = $ settings ['content_word_pc ' ];
@@ -956,11 +989,18 @@ protected function render()
956989
957990 foreach ($ posts as $ post ) {
958991 $ post_title = get_the_title ($ post ->ID );
959- $ post_content = wp_trim_words ($ post ->post_content , $ wordPc );
992+ if (wp_is_mobile ()){
993+ $ post_content = wp_trim_words ($ post ->post_content , $ wordMobile );
994+ }
995+ else {
996+ $ post_content = wp_trim_words ($ post ->post_content , $ wordPc );
997+
998+ }
960999 $ post_date = get_the_date ('j F Y ' , $ post ->ID );
9611000 $ post_link = get_permalink ($ post ->ID );
9621001 $ tags = get_the_tags ($ post ->ID );
963- $ tags_active =$ settings ['tag_active ' ];
1002+ $ post_numb = get_the_date ('Y-m-d ' ,$ post ->ID );
1003+ $ date_array = explode ('- ' , $ post_numb );
9641004 // Check if the post has a featured image
9651005 $ featured_image = get_the_post_thumbnail_url ($ post ->ID );
9661006 if (!$ featured_image ) {
@@ -969,9 +1009,15 @@ protected function render()
9691009 }
9701010 if (is_admin ()) {
9711011 echo '<div class="card2" style="background-image: url( ' . $ featured_image . '); "> ' ;
972- } else {
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 '"> ' ;}
1012+ }
1013+ else {
1014+ if (wp_is_mobile ()){
1015+ echo '<div class="card2" style="background-image: url( ' . $ featured_image . '); > ' ;
1016+
1017+ }
1018+ else {
1019+ echo '<div class="card2" style="background-image: url( ' . $ featured_image . ')" onclick="window.location.href= \'' . $ post_link . '\'"> ' ;
1020+ }
9751021 }
9761022 echo '
9771023 <div class="info">
@@ -985,26 +1031,36 @@ protected function render()
9851031 } }
9861032 else {
9871033 foreach ($ tags as $ tag ) {
1034+
9881035 echo '<a href=" ' . get_tag_link ($ tag ->term_id ) . '" class="tag"> ' . $ tag ->name . '</a> ' ;
9891036 } }
9901037 }
9911038 $ date_parts = explode (' ' , $ post_date );
1039+ $ i =2 ;
1040+ $ date_array [1 ]=$ date_array [0 ].'/ ' .$ date_array [1 ];
1041+ $ date_array [2 ]=$ date_array [1 ].'/ ' .$ date_array [2 ];
9921042 if ($ selected_page_id != 0 ) {
9931043 $ page_link = get_permalink ($ selected_page_id );
1044+ echo '<div> ' ;
9941045 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- }
1046+ if ($ i ==1 ){
1047+ $ date_array [1 ]= $ date_array [1 ].'/01 ' ;
1048+ }
1049+ $ date_link = add_query_arg ('date ' , $ date_array [$ i ], $ page_link );
1050+ echo ' <a href=" ' . $ date_link . '" class="date"> ' . ucfirst ($ part ) . '</a> ' ;
1051+ $ i -=1 ;
1052+
1053+ }
1054+ echo '</div> ' ;
9991055} else {
10001056 echo '<div> ' ;
1057+ $ i =2 ;
10011058 foreach ($ date_parts as $ part ) {
1002- $ date_link = get_day_link ( $ post -> post_year , $ post -> post_month , $ post -> post_day , $ post -> ID ) ;
1059+ $ date_link = home_url (). ' / ' . $ date_array [ $ i ] ;
10031060 echo '<a href=" ' . $ date_link . '" class="date"> ' . ucfirst ($ part ) . '</a> ' ;
1061+ $ i -=1 ;
10041062
10051063 } echo '</div> ' ;
1006-
1007-
10081064}
10091065 if ($ selected_page_id != 0 ) {
10101066 $ page_link = get_permalink ($ selected_page_id );
0 commit comments