Skip to content

Commit 8ab367f

Browse files
committed
prova excerp
1 parent 306bebd commit 8ab367f

2 files changed

Lines changed: 33 additions & 39 deletions

File tree

Open-Elementor-Widget.php

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11
<?php
22
/*
3-
Plugin Name: OpenElementorWidget
3+
Plugin Name:orWidget
44
Description: Custom widget for Elementor
55
Version: 1.0
66
Author: Davide
77
*/
88

99
// Register the custom widgets with Elementor
10-
function enqueue_font_awesome()
11-
{
12-
wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.0/css/all.min.css', array(), '6.1.0');
13-
}
14-
add_action('elementor/frontend/after_enqueue_styles', 'enqueue_font_awesome');
10+
add_filter('get_the_excerpt', function ($excerpt) {
11+
12+
$excerpt_length = 40; // Change excerpt length
13+
14+
global $post;
15+
16+
if (
17+
is_archive() || is_search()
18+
) {
19+
$post = get_post();
20+
}
21+
22+
if (
23+
has_excerpt($post)
24+
) {
25+
} else {
26+
$content = get_the_content();
27+
$first_word = substr($content, 0, strpos($content, ' '));
28+
$content = substr($content, strpos($content, ' ') + 2);
29+
$excerpt = wp_trim_words($content, $excerpt_length);
30+
$excerpt = $first_word . ' ' . $excerpt;
31+
}
32+
33+
return $excerpt;
34+
}, 10, 2);
1535
add_action('elementor/widgets/widgets_registered', 'register_OpenElementorWidget_widgets');
16-
<<<<<<< HEAD
1736

1837
function add_elementor_widget_categories($elements_manager)
1938
{
20-
=======
21-
function add_elementor_widget_categories( $elements_manager ) {
22-
>>>>>>> d490c19b4b50f0986a1212da8bccc90d5009ca3e
2339

2440
$elements_manager->add_category(
2541
'OpenWidget',
@@ -32,25 +48,7 @@ function add_elementor_widget_categories( $elements_manager ) {
3248
add_action('elementor/elements/categories_registered', 'add_elementor_widget_categories');
3349
function register_OpenElementorWidget_widgets($widgets_manager)
3450
{
35-
<<<<<<< HEAD
3651
// Include and register the latest-posts-hover widget
3752
require_once(plugin_dir_path(__FILE__) . 'widgets/Latest-Posts-Hover.php');
3853
$widgets_manager->register_widget_type(new \Latest_Posts_Hover_Widget());
3954
}
40-
=======
41-
add_action( 'elementor/element/before_render', function( $element, $element_id, $settings ) {
42-
if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) {
43-
// Disabilita il link solo se l'elemento contiene un link
44-
$link = $element->get_settings('link');
45-
if ( ! empty( $link ) ) {
46-
$element->add_render_attribute( '_wrapper', 'href', '' );
47-
}
48-
echo'prova';
49-
}
50-
}, 10, 3 );
51-
// Include and register the latest-posts-hover widget
52-
require_once(plugin_dir_path(__FILE__) . 'widgets/Latest-Posts-Hover.php');
53-
$widgets_manager->register_widget_type(new \Latest_Posts_Hover_Widget());
54-
55-
}
56-
>>>>>>> d490c19b4b50f0986a1212da8bccc90d5009ca3e

widgets/Latest-Posts-Hover.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public function get_name()
1111
{
1212
return 'latest-posts-hover';
1313
}
14-
1514
public function get_title()
1615
{
1716
return esc_html__('Latest Posts Hover', 'latest-posts-hover');
@@ -26,6 +25,7 @@ public function get_categories()
2625
{
2726
return ['OpenWidget'];
2827
}
28+
2929
protected function _register_controls()
3030
{
3131
$this->start_controls_section(
@@ -98,6 +98,7 @@ protected function _register_controls()
9898
);
9999

100100
$this->end_controls_section();
101+
101102
$this->start_controls_section(
102103
'section_title',
103104
[
@@ -790,6 +791,7 @@ private function get_pages()
790791
}
791792
return $options;
792793
}
794+
793795
protected function render()
794796

795797
{
@@ -816,11 +818,6 @@ protected function render()
816818
$args = [
817819
'posts_per_page' => -1,
818820
];
819-
echo '<script>
820-
const selectedPageControl = elementor.settings.page.controls.selected_page;
821-
822-
// Imposta il valore desiderato per il controllo
823-
selectedPageControl.setValue(' . get_the_ID() . '); </script>'; // Sostituisci 10 con l'ID pagina desiderato
824821
}
825822

826823
$posts = get_posts($args);
@@ -883,7 +880,7 @@ protected function render()
883880
echo '<div class="categories-links">';
884881
foreach ($categories as $category) {
885882
$category_link = add_query_arg('category', $category->slug, $page_link);
886-
echo '<a href="' . $category_link . '" class="category">' . $category->name . '</a>';
883+
echo '<a href="' . $category_link . '" class="category"> ' . $category->name . '&nbsp; </a>';
887884
}
888885
echo '</div>';
889886
}
@@ -892,7 +889,7 @@ protected function render()
892889
if (!empty($categories)) {
893890
echo '<div class="categories-links">';
894891
foreach ($categories as $category) {
895-
echo '<a href="' . get_category_link($category->term_id) . '" class="category">' . $category->name . '</a>';
892+
echo '<a href="' . get_category_link($category->term_id) . '" class="category"> ' . $category->name . '&nbsp; </a>';
896893
}
897894
echo '</div>';
898895
}
@@ -931,7 +928,7 @@ protected function render()
931928
echo '<div class="categories-links">';
932929
foreach ($categories as $category) {
933930
$category_link = add_query_arg('category', $category->slug, $page_link);
934-
echo '<a href="' . $category_link . '" class="category">' . $category->name . '</a>';
931+
echo '<a href="' . $category_link . '" class="category"> ' . $category->name . '<br>; </a>';
935932
}
936933
echo '</div>';
937934
}
@@ -940,7 +937,7 @@ protected function render()
940937
if (!empty($categories)) {
941938
echo '<div class="categories-links">';
942939
foreach ($categories as $category) {
943-
echo '<a href="' . get_category_link($category->term_id) . '" class="category">' . $category->name . '</a>';
940+
echo '<a href="' . get_category_link($category->term_id) . '" class="category"> ' . $category->name . '&nbsp; </a>';
944941
}
945942
echo '</div>';
946943
}
@@ -1071,7 +1068,6 @@ protected function render()
10711068
.category {
10721069
margin-top: 0px;
10731070
margin-bottom: 0px;
1074-
padding: 0 5px;
10751071
font-size: 18px;
10761072
color:black;
10771073
display:none;

0 commit comments

Comments
 (0)