我在函数中使用此代码。php:Issue with enabling formatting in excerpts in Wordpress
允许在摘录中使用短代码、javascript和格式-非常好,谢谢。
然而,我也使用了一个滑块(幻灯片播放卫星),如果我将摘录长度设置得太低(幻灯片大小显然与其内容相关),滑块就会断裂。有没有人知道如何保持摘录的长度较低,但当一篇文章有一个由短代码调用的播放器/滑块时,请确保它完成了嵌入的代码,无论它有多长?
谢谢
功能。php:
function better_trim_excerpt($text)
{
$raw_excerpt = $text;
if ( \'\' == $text ) {
$text = get_the_content(\'\');
//$text = strip_shortcodes( $text );
$text = apply_filters(\'the_content\', $text);
$text = str_replace(\']]>\', \']]>\', $text);
// Enable formatting in excerpts - Add HTML tags that you want to be parsed in excerpts, default is 55
//$text = strip_tags($text, \'<strong><b><em><i><a><code><kbd><img>\');
// Set custom excerpt length - number of words to be shown in excerpts
$excerpt_length = apply_filters(\'excerpt_length\', 900);
// Modify excerpt more string at the end from [...] to ...
$excerpt_more = apply_filters(\'excerpt_more\', \' \' . \'...\');
$words = preg_split("/[\\n\\r\\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$text = implode(\' \', $words);
// IMPORTANT! Prevents tags cutoff by excerpt (i.e. unclosed tags) from breaking formatting
$text = force_balance_tags( $text );
$text = $text . $excerpt_more;
} else {
$text = implode(\' \', $words);
}
}
return apply_filters(\'wp_trim_excerpt\', $text, $raw_excerpt);
}
// Remove the native excerpt function, and replace it with our improved function
remove_filter(\'get_the_excerpt\', \'wp_trim_excerpt\');
add_filter(\'get_the_excerpt\', \'better_trim_excerpt\');
幻灯片放映卫星默认设置。php:
<?php
global $satellite_init_ok;
if (!empty($slides)) :
$style = $this->get_option(\'styles\');
$images = $this->get_option(\'Images\');
$imagesbox = $images[\'imagesbox\'];
$pagelink = $images[\'pagelink\'];
$textloc = $this->get_option(\'textlocation\');
$responsive = $this->get_option(\'responsive\');
$respExtra = (isset($respExtra)) ? $respExtra : 0;
$align = $this->get_option(\'align\');
if (!$frompost) {
$this->Gallery->loadData($slides[0]->section);
$sidetext = $this -> Gallery -> capLocation($this->Gallery->data->capposition,$slides[0]->section);
}
?>
<?php if ($frompost) : ?>
<!-- =======================================
THE ORBIT SLIDER CONTENT
======================================= -->
<div class="orbit-default
<?php echo($this->get_option(\'thumbnails_temp\') == \'Y\') ? \' default-thumbs\' : \'\'; ?>
<?php echo($align) ? \' satl-align-\' . $align : \'\'; ?>
<?php echo($responsive) ? \' resp\' : \'\'; ?>
">
<div id="featured<?php echo $satellite_init_ok; ?>">
<?php foreach ($slides as $slider) :
$thumbnail_link = wp_get_attachment_image_src($slider->ID, \'thumbnail\', false);
$attachment_link = get_attachment_link($slider->ID);
$class= ($images[\'position\'] == "S") ? "stretchCenter" : "absoluteCenter";
echo "<div class=\'sorbit-wide ".$class."\'
data-caption=\'#post-{$slider->ID}\'
data-thumb=\'{$thumbnail_link[0]}\'>";
$this->render(\'display-image\',
array(\'frompost\' => true,
\'slider\' => $slider), true, \'orbit\');?>
</div>
<?php $this -> render(\'display-caption\',
array( \'frompost\' => true,
\'slider\' => $slider,
\'fontsize\' => null,
\'style\' => $style,
\'i\' => null
), true, \'orbit\');?>
<?php endforeach; ?>
</div> <!-- end featured -->
</div>
<?php $this -> render(\'jsinit\', array(\'gallery\'=>false,\'frompost\' => true,\'respExtra\' => 0), true, \'orbit\');?>
<!-- CUSTOM GALLERY -->
<?php else : ?>
<div class="orbit-default
<?php echo($this->get_option(\'thumbnails_temp\') == \'Y\') ? \' default-thumbs\' : \'\'; ?>
<?php echo($sidetext) ? \' text-\' . $sidetext : \'\'; ?>
<?php echo($align) ? \' satl-align-\' . $align : \'\'; ?>
<?php echo($responsive) ? \' resp\' : \'\'; ?>
">
<div id="featured<?php echo $satellite_init_ok; ?>">
<?php $i = 0; ?>
<?php foreach ($slides as $slider) : ?>
<?php
$class= ($images[\'position\'] == "S") ? "stretchCenter" : "absoluteCenter";
echo "<div id=\'satl-custom-{$this->Gallery->data->id}{$slider->id}\' class=\'sorbit-wide ".$class."\'
data-caption=\'#custom{$satellite_init_ok}-$i\'
data-thumb=\'{$this->Html->image_url($this->Html->thumbname($slider->image))}\'>";
$this->render(\'display-image\',
array(\'frompost\' =>false,
\'slider\' => $slider), true, \'orbit\');?>
</div>
<?php
if ($sidetext != ( "Disabled" )) :
if ($slider->textlocation != "N") :
?>
<?php $this -> render(\'display-caption\',
array( \'frompost\' => false,
\'slider\' => $slider,
\'fontsize\' => $this->Gallery->data->font,
\'style\' => $style,
\'i\' => $i
), true, \'orbit\');?>
<?php else : ?>
<span class="sattext-none" id=\'custom<?php echo ($satellite_init_ok . \'-\' . $i); ?>\'>
</span>
<?php
endif;
endif;
$i = $i + 1;
endforeach;
?>
</div>
</div>
<?php $this -> render(\'jsinit\', array(\'gallery\'=>$slides[0]->section,\'frompost\' => false, \'respExtra\' => $respExtra), true, \'orbit\');?>
<?php
endif;
/* * ****** PRO ONLY ************* */
if (SATL_PRO && $this->get_option(\'keyboard\') == \'Y\') {
require SATL_PLUGIN_DIR . \'/pro/keyboard.html\';
}
endif;
?>