SORU
2 Kasım 2010, Salı


Wordpress çoklu alıntı uzunlukları

Başlıkta yazdığı gibi, WordPress çoklu alıntı uzunlukları arıyorum.

Functions.php bunu yapabilirsiniz anlıyorum:

function twentyten_excerpt_length( $length ) {
    return 15;
}
add_filter( 'excerpt_length', 'twentyten_excerpt_length' );

Ne bilmek istiyorum nasıl olabilir birden fazla bu her dönen farklı sayısal değerler yani kısa alıntılar için kenar döngüler, uzun alıntılar için öne çıkan döngüler, ve en uzun alıntı için ana madde.

Şablonlar bu kullanmak gibi bir şey:

<?php the_excerpt('length-short') ?>
<?php the_excerpt('length-medium') ?>
<?php the_excerpt('length-long') ?>

Eyvallah, Dave

CEVAP
3 Kasım 2010, ÇARŞAMBA


Ne dersin?

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;
    }

    function content($limit) {
      $content = explode(' ', get_the_content(), $limit);
      if (count($content)>=$limit) {
        array_pop($content);
        $content = implode(" ",$content).'...';
      } else {
        $content = implode(" ",$content);
      } 
      $content = preg_replace('/\[. \]/','', $content);
      $content = apply_filters('the_content', $content); 
      $content = str_replace(']]>', ']]>', $content);
      return $content;
    }

şablon kodunuzda sadece.. kullanın

<?php echo excerpt(25); ?>

kimden: http://bavotasan.com/tutorials/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • AutoklubZAPRESIC

    AutoklubZAPR

    17 Mayıs 2011
  • Barnacules Nerdgasm

    Barnacules N

    20 Temmuz 2006
  • Microsoft Research

    Microsoft Re

    24 EKİM 2008