Skip to content

Commit c29dcea

Browse files
committed
2 parents 20fd77f + 8ab367f commit c29dcea

2 files changed

Lines changed: 34 additions & 26 deletions

File tree

Open-Elementor-Widget.php

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
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-
add_action( 'wp_enqueue_scripts', 'dequeue_parent_theme_styles', 20 );
11-
function dequeue_parent_theme_styles() {
12-
if ( ! is_admin() ) {
13-
wp_dequeue_style( 'parent-style' );
14-
wp_dequeue_style( 'parent-style-rtl' );
15-
}
16-
}
17-
function my_custom_excerpt() {
18-
$content=get_the_content();
19-
$excerpt=wp_trim_words( $content, 30 );
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+
2033
return $excerpt;
21-
22-
}
23-
24-
add_filter( 'get_the_excerpt', 'my_custom_excerpt' );
34+
}, 10, 2);
2535
add_action('elementor/widgets/widgets_registered', 'register_OpenElementorWidget_widgets');
2636

2737
function add_elementor_widget_categories($elements_manager)
@@ -41,4 +51,4 @@ function register_OpenElementorWidget_widgets($widgets_manager)
4151
// Include and register the latest-posts-hover widget
4252
require_once(plugin_dir_path(__FILE__) . 'widgets/Latest-Posts-Hover.php');
4353
$widgets_manager->register_widget_type(new \Latest_Posts_Hover_Widget());
44-
}
54+
}

widgets/Latest-Posts-Hover.php

Lines changed: 8 additions & 10 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,7 +25,7 @@ public function get_categories()
2625
{
2726
return ['OpenWidget'];
2827
}
29-
28+
3029
protected function _register_controls()
3130
{
3231
$this->start_controls_section(
@@ -87,7 +86,7 @@ protected function _register_controls()
8786
],
8887
]
8988
);
90-
89+
9190
$this->add_control(
9291
'selected_page',
9392
[
@@ -98,7 +97,7 @@ protected function _register_controls()
9897
]
9998
);
10099

101-
$this->end_controls_section();
100+
$this->end_controls_section();
102101

103102
$this->start_controls_section(
104103
'section_title',
@@ -792,11 +791,11 @@ private function get_pages()
792791
}
793792
return $options;
794793
}
795-
protected function render()
796794

797-
{
798-
$settings = $this->get_settings_for_display();
795+
protected function render()
799796

797+
{
798+
$settings = $this->get_settings_for_display();
800799
if ($settings['posts_per_page'] == null) {
801800
$settings['posts_per_page'] = 4;
802801
}
@@ -819,7 +818,6 @@ protected function render()
819818
$args = [
820819
'posts_per_page' => -1,
821820
];
822-
823821
}
824822

825823
$posts = get_posts($args);
@@ -930,7 +928,7 @@ protected function render()
930928
echo '<div class="categories-links">';
931929
foreach ($categories as $category) {
932930
$category_link = add_query_arg('category', $category->slug, $page_link);
933-
echo '<a href="' . $category_link . '" class="category"> ' . $category->name . '&nbsp; </a>';
931+
echo '<a href="' . $category_link . '" class="category"> ' . $category->name . '<br>; </a>';
934932
}
935933
echo '</div>';
936934
}
@@ -1118,4 +1116,4 @@ protected function render()
11181116
11191117
</style>';
11201118
}
1121-
}
1119+
}

0 commit comments

Comments
 (0)