Anonymous
Отрывок Wordpress с допустимыми тегами не работает?
Сообщение
Anonymous » 09 окт 2024, 01:27
Я пытаюсь создать плагин простого отрывка в Wordpress. Я много гуглил, допустимый тег не работает. Может ли кто-нибудь подсказать, как это сделать?
Код: Выделить всё
class fpexcerpt {
function __construct() {
require_once('inc/template.php');
if(isset($_POST['reset'])) {
add_action('admin_init',array($this,'fpexcerptrestore'));
}
}
function fpexcerptdefault() {
add_option('fpexcerptcount',55);
add_option('fpexcerptmore','[...]');
}
function fpexcerptrestore() {
delete_option('fpexcerpttag');
delete_option('fpexcerptcount');
delete_option('fpexcerptmore');
fpexcerpt::fpexcerptdefault();
}
function fpexcerptadmin() {
add_submenu_page('options-general.php','Fantastic Excerpt', 'Fantastic Excerpt', 'manage_options','fpexcerptadmin', 'fpexcerptadmin_menu');
}
function fpexcerptupdate() {
register_setting('fpexcpt','fpexcerpttag');
register_setting('fpexcpt','fpexcerptcount');
register_setting('fpexcpt','fpexcerptmore');
}
function improved_trim_excerpt($text) {
global $post;
if ( '' == $text ) {
$text = get_the_excerpt();
$text = apply_filters('the_excerpt',$text);
// $text = str_replace('\]\]\>', ']]>', $text);
$text = strip_tags($text, '');
$excerpt_length = 80;
$words = explode(' ', $text, $excerpt_length + 1);
if (count($words)> $excerpt_length) {
array_pop($words);
array_push($words, '[...]');
$text = implode(' ', $words);
}
}
return $text;
}
}
$new = new fpexcerpt();
register_activation_hook(__FILE__,array('fpexcerpt','fpexcerptdefault'));
//remove_all_filters('wp_trim_excerpt');
//add_filter('get_the_excerpt', array('fpexcerpt','fpexcerptprocess'));
remove_filter('get_the_excerpt',array('fpexcerpt','wp_trim_excerpt'));
add_filter('get_the_excerpt', array('fpexcerpt','improved_trim_excerpt'));
add_action('admin_menu',array('fpexcerpt','fpexcerptadmin'));
add_action('admin_init',array('fpexcerpt','fpexcerptupdate'));
?>
РЕДАКТИРОВАТЬ:
[img]
https://i.sstatic . net/n8mCW.png[/img]
Первое изображение показывает содержание отрывка, когда я нажимаю на конкретную публикацию, на которую он получает ссылку, но не в отрывке, даже если я добавляю отрывок плагин (мой)
Подробнее здесь:
https://stackoverflow.com/questions/167 ... ot-working
1728426427
Anonymous
Я пытаюсь создать плагин простого отрывка в Wordpress. Я много гуглил, допустимый тег не работает. Может ли кто-нибудь подсказать, как это сделать? [code] class fpexcerpt { function __construct() { require_once('inc/template.php'); if(isset($_POST['reset'])) { add_action('admin_init',array($this,'fpexcerptrestore')); } } function fpexcerptdefault() { add_option('fpexcerptcount',55); add_option('fpexcerptmore','[...]'); } function fpexcerptrestore() { delete_option('fpexcerpttag'); delete_option('fpexcerptcount'); delete_option('fpexcerptmore'); fpexcerpt::fpexcerptdefault(); } function fpexcerptadmin() { add_submenu_page('options-general.php','Fantastic Excerpt', 'Fantastic Excerpt', 'manage_options','fpexcerptadmin', 'fpexcerptadmin_menu'); } function fpexcerptupdate() { register_setting('fpexcpt','fpexcerpttag'); register_setting('fpexcpt','fpexcerptcount'); register_setting('fpexcpt','fpexcerptmore'); } function improved_trim_excerpt($text) { global $post; if ( '' == $text ) { $text = get_the_excerpt(); $text = apply_filters('the_excerpt',$text); // $text = str_replace('\]\]\>', ']]>', $text); $text = strip_tags($text, ''); $excerpt_length = 80; $words = explode(' ', $text, $excerpt_length + 1); if (count($words)> $excerpt_length) { array_pop($words); array_push($words, '[...]'); $text = implode(' ', $words); } } return $text; } } $new = new fpexcerpt(); register_activation_hook(__FILE__,array('fpexcerpt','fpexcerptdefault')); //remove_all_filters('wp_trim_excerpt'); //add_filter('get_the_excerpt', array('fpexcerpt','fpexcerptprocess')); remove_filter('get_the_excerpt',array('fpexcerpt','wp_trim_excerpt')); add_filter('get_the_excerpt', array('fpexcerpt','improved_trim_excerpt')); add_action('admin_menu',array('fpexcerpt','fpexcerptadmin')); add_action('admin_init',array('fpexcerpt','fpexcerptupdate')); ?> [/code] [b]РЕДАКТИРОВАТЬ:[/b] [img] https://i.sstatic.net/glEKG.png[/img] [img]https://i.sstatic. net/n8mCW.png[/img] Первое изображение показывает содержание отрывка, когда я нажимаю на конкретную публикацию, на которую он получает ссылку, но не в отрывке, даже если я добавляю отрывок плагин (мой) Подробнее здесь: [url]https://stackoverflow.com/questions/16794045/wordpress-excerpt-with-allowable-tags-is-not-working[/url]