如何在使用滑块或球员的快捷码时阻止摘录中不需要的拆分

时间:2013-09-11 作者:Sug Mon Kooky

我在函数中使用此代码。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;
?>

1 个回复
SO网友:s_ha_dum

添加remove_filter(\'get_the_excerpt\', \'bwp_trim_excerpt\');, 或者在幻灯片播放之前,将回调命名为任何名称,然后再将其添加回来。

如果没有回调和滑块的实际代码,我想我做得不会更好。

结束

相关推荐

Loading shortcode with ajax

如果浏览器的屏幕大小特定,我会尝试加载幻灯片,也就是说,我不希望幻灯片加载到更小的移动屏幕上。幻灯片放映插件提供了一个短代码:<?php echo do_shortcode(\'[metaslider id=\"8302\"]\'); ?> 但当我试着加载它时。load(),它只是输出字符串,不运行php。因此,环顾四周,似乎有几个帖子与此相关:call shortcode in javascriptWhy might a plugin's 'do_shortcode