0

Web サイトで Modern Tribe の Events Calendar を使用していますが、ウィジェットを変更したいと考えています。私は、1 つの小さな詳細を除いて、私が望むようにすべてを持っています... 抜粋. これは、イベントの説明を取得するコードのセクションが Web サイトでどのように見えるかです。しかし、ウィジェットの完全な説明は必要ありません... 10 語程度しかなく、その後に省略記号 (...) が続きます。何かご意見は?

<div class="entry-content tribe-events-event-entry" itemprop="description">
    <?php if (has_excerpt ()): ?>
        <?php the_excerpt(); ?>
    <?php else: ?>
        <?php the_content(); ?>
    <?php endif; ?>
</div> <!-- End tribe-events-event-entry -->
4

8 に答える 8

4

これを functions.php ファイルに追加してみてください。the_excerpt の詳細については、 http ://codex.wordpress.org/Function_Reference/the_excerpt を参照してください。

function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
于 2013-05-16T02:50:44.803 に答える
2

これを使用して、カスタムの抜粋を作成できます

// get the post content     
<?php $content = get_the_content(); ?>
<?php
// get the first 80 words from the content and added to the $abstract variable
 preg_match('/^([^.!?\s]*[\.!?\s]+){0,80}/', strip_tags($content), $abstract);
  // pregmatch will return an array and the first 80 chars will be in the first element 
  echo $abstract[0] . '...';
    ?>  

このチュートリアル http://www.kavoir.com/2009/02/php-generating-summary-abstract-from-a-text-or-html-string-limiting-by-words-or-sentences からこれを採用しました。 html お 役に立てば幸いです

于 2013-05-16T17:52:36.917 に答える
1

このコードをfunction.phpに入れます

 
function word_count($string, $limit) {
 
$words = explode(' ', $string);
 
return implode(' ', array_slice($words, 0, $limit));
 
}
 

それで

<?php the_content() ?> or <?php the_excerpt() ?>コードを置き換えるものは何でも

これ:-

<?php echo word_count(get_the_excerpt(), '30'); ?>
于 2014-04-08T11:57:47.150 に答える
1

次のコード functions.php を追加します

function custom_excerpt_length( $length ) {
    return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

the_excerpt に関する詳しい情報はこちら: http://www.happiweb.net/2014/05/gioi-han-tu-trong-mo-ta-theexcerpt-cua.html

于 2014-05-15T01:41:59.383 に答える
0

プラグインなしで抜粋の単語数を制限する解決策を見つけました。次のコードを functions.php ファイルに追加します。

<?php
// Custom Excerpt 
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
} 
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
?>

ここで、ループで the_content() または the_excerpt を使用する代わりに、excerpt($limit) または content($limit) を使用します。抜粋を 25 語に制限する場合、コードは次のようになります。

<?php echo excerpt(25); ?>

ここで抜粋の単語数を制限する解決策を得ました

于 2015-01-23T10:01:15.927 に答える
-2

純粋な css を使用し、このタイプのコードを使用して、100px のテキストの末尾に省略記号を取得できます。

max-width: 100px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
于 2013-05-16T02:58:08.333 に答える