1. Halo Guest, pastikan Anda selalu menaati peraturan forum sebelum mengirimkan post atau thread baru.

Mainan 'content excerpt'

Discussion in 'Wordpress' started by mqhidayat, Jun 19, 2010.

  1. mqhidayat

    mqhidayat Super Hero

    Joined:
    Sep 24, 2008
    Messages:
    1,289
    Likes Received:
    151
    Location:
    Ngalam
    Saia bingung nih buat judul. mudah2an bisa dimengerti judul yg saia tulis.
    Thread ini mudah2an bisa njawab pertanyaan yg ada di sini.

    Yang sudah sering pake wordpress, apalagi yg sering nguprek2 theme WP, mungkin bahasan ini sudah basi.
    tapi tak ada salahnya jika kita berbagi lagi di sini.

    Cara bikin read more otomatis di halaman index, arsip, & hasil pencarian dg The Excerpt Reloaded
    Berikut beberapa yg harus ditamahkan dan dirubah dari script theme WP yg digunakan:
    1. functions.php
    bisa download di
    Code:
    _http://robsnotebook.com/the-excerpt-reloaded/
    ato copas script berikut:
    <?php
    /*
    Plugin Name: the_excerpt Reloaded
    Plugin URI: http://robsnotebook.com/the-excerpt-reloaded/
    Description: This mod of WordPress' template function the_excerpt() knows there is no spoon.
    Version: R1.4
    Author: Kaf Oseo, Rob Bresalier
    Author URI: http://robsnotebook.com

    Copyright (c) 2007 Rob Bresalier (http://robsnotebook.com)
    Copyright (c) 2004, 2005 Kaf Oseo (http://szub.net)
    the_excerpt Reloaded is released under the GNU General Public
    License: http://www.gnu.org/licenses/gpl.txt

    This is a WordPress plugin (http://wordpress.org). WordPress is
    free software; you can redistribute it and/or modify it under the
    terms of the GNU General Public License as published by the Free
    Software Foundation; either version 2 of the License, or (at your
    option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.

    For a copy of the GNU General Public License, write to:

    Free Software Foundation, Inc.
    59 Temple Place, Suite 330
    Boston, MA 02111-1307
    USA

    You can also view a copy of the HTML version of the GNU General
    Public License at http://www.gnu.org/copyleft/gpl.html

    */

    function wp_the_excerpt_reloaded($args='') {
    parse_str($args);
    if(!isset($excerpt_length)) $excerpt_length = 35; // length of excerpt in words. -1 to display all excerpt/content
    if(!isset($allowedtags)) $allowedtags = '<a>'; // HTML tags allowed in excerpt, 'all' to allow all tags.
    if(!isset($filter_type)) $filter_type = 'none'; // format filter used => 'content', 'excerpt', 'content_rss', 'excerpt_rss', 'none'
    if(!isset($use_more_link)) $use_more_link = 1; // display
    if(!isset($more_link_text)) $more_link_text = "(more...)";
    if(!isset($force_more)) $force_more = 1;
    if(!isset($fakeit)) $fakeit = 1;
    if(!isset($fix_tags)) $fix_tags = 1;
    if(!isset($no_more)) $no_more = 0;
    if(!isset($more_tag)) $more_tag = 'div';
    if(!isset($more_link_title)) $more_link_title = 'Continue reading this entry';
    if(!isset($showdots)) $showdots = 1;

    return the_excerpt_reloaded($excerpt_length, $allowedtags, $filter_type, $use_more_link, $more_link_text, $force_more, $fakeit, $fix_tags, $no_more, $more_tag, $more_link_title, $showdots);
    }

    function the_excerpt_reloaded($excerpt_length=35, $allowedtags='<a>', $filter_type='none', $use_more_link=true, $more_link_text="(more...)", $force_more=true, $fakeit=1, $fix_tags=true, $no_more=false, $more_tag='div', $more_link_title='Continue reading this entry', $showdots=true) {
    if(preg_match('%^content($|_rss)|^excerpt($|_rss)%', $filter_type)) {
    $filter_type = 'the_' . $filter_type;
    }
    echo get_the_excerpt_reloaded($excerpt_length, $allowedtags, $filter_type, $use_more_link, $more_link_text, $force_more, $fakeit, $fix_tags, $no_more, $more_tag, $more_link_title, $showdots);
    }

    function get_the_excerpt_reloaded($excerpt_length, $allowedtags, $filter_type, $use_more_link, $more_link_text, $force_more, $fakeit, $fix_tags, $no_more, $more_tag, $more_link_title, $showdots) {
    global $post;

    if (!empty($post->post_password)) { // if there's a password
    if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match cookie
    if(is_feed()) { // if this runs in a feed
    $output = __('There is no excerpt because this is a protected post.');
    } else {
    $output = get_the_password_form();
    }
    }
    return $output;
    }

    if($fakeit == 2) { // force content as excerpt
    $text = $post->post_content;
    } elseif($fakeit == 1) { // content as excerpt, if no excerpt
    $text = (empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt;
    } else { // excerpt no matter what
    $text = $post->post_excerpt;
    }

    if($excerpt_length < 0) {
    $output = $text;
    } else {
    if(!$no_more && strpos($text, '<!--more-->')) {
    $text = explode('<!--more-->', $text, 2);
    $l = count($text[0]);
    $more_link = 1;
    } else {
    $text = explode(' ', $text);
    if(count($text) > $excerpt_length) {
    $l = $excerpt_length;
    $ellipsis = 1;
    } else {
    $l = count($text);
    $more_link_text = '';
    $ellipsis = 0;
    }
    }
    for ($i=0; $i<$l; $i++)
    $output .= $text[$i] . ' ';
    }

    if('all' != $allowedtags) {
    $output = strip_tags($output, $allowedtags);
    }

    // $output = str_replace(array("\r\n", "\r", "\n", " "), " ", $output);

    $output = rtrim($output, "\s\n\t\r\0\x0B");
    $output = ($fix_tags) ? balanceTags($output, true) : $output;
    $output .= ($showdots && $ellipsis) ? '' : '';
    $output = apply_filters($filter_type, $output);

    switch($more_tag) {
    case('div') :
    $tag = 'div';
    break;
    case('span') :
    $tag = 'span';
    break;
    case('p') :
    $tag = 'p';
    break;
    default :
    $tag = 'span';
    }

    if ($use_more_link && $more_link_text) {
    if($force_more) {
    $output .= ' <' . $tag . ' class="more-link"><a href="'. get_permalink($post->ID) . '#more-' . $post->ID .'" title="' . $more_link_title . '">' . $more_link_text . '</a></' . $tag . '>' . "\n";
    } else {
    $output .= ' <' . $tag . ' class="more-link"><a href="'. get_permalink($post->ID) . '" title="' . $more_link_title . '">' . $more_link_text . '</a></' . $tag . '>' . "\n";
    }
    }

    return $output;
    }
    ?>

    2. index.php - archives.php - search.php
    Ganti code berikut:
    <?php the_content(); ?>
    dengan
    <?php the_excerpt_reloaded();?>


    Ini beberapa parameter yg bisa digunakan pada the_excerpt_reloaded
    Ambil saja contoh ini:
    HTML:
    <?php the_excerpt_reloaded(100, ‘<img><p>’, ‘’, FALSE, ‘Read more &raquo;’, TRUE); ?>
    Yang saia tahu dari script itu,
    100 kata awal kontent yg akan ditampilkan.
    tag html <img>, <p> akan ditampilkan.
    bagian akhir potongan akan ada read more.

    Untuk lainnya, silahkan bereksperimen sendiri. :silau:

    Catatan:
    kode untuk functions.php yg ada di spoiler itu sudah tak rubah sedkit.
     
    Last edited: Jun 19, 2010
    xtmxady and hadie87 like this.
  2. hadie87

    hadie87 Densus 99

    Joined:
    Sep 10, 2009
    Messages:
    5,920
    Likes Received:
    3,046
    Location:
    Baturaja, Indonesia
    Wah, mantab gan. ane coba dulu ya:senyum:
     
  3. arifudin

    arifudin Super Hero

    Joined:
    Dec 20, 2009
    Messages:
    2,016
    Likes Received:
    148
    Location:
    Arifudin.wordpress.com
    bookmark dolo gan, :senyum:
     
  4. gembel-intelek

    gembel-intelek Lurker

    Joined:
    Mar 29, 2009
    Messages:
    4,341
    Likes Received:
    907
    Location:
    New Coral
    Ada cara lebih simple, pi thanks dah share.. :D
     
  5. ar_nardi

    ar_nardi Super Hero

    Joined:
    Mar 16, 2010
    Messages:
    2,346
    Likes Received:
    188
    Location:
    Ujungnya Samarinda
    share dulu sob cara simple nya :senyum:
     
  6. gembel-intelek

    gembel-intelek Lurker

    Joined:
    Mar 29, 2009
    Messages:
    4,341
    Likes Received:
    907
    Location:
    New Coral
    index.php - archives.php - search.php

    ganti

    Code:
      <?php the_content(); ?>
    dgn
    Code:
    <?php
        $content = get_the_content('',FALSE,'');
        $content = apply_filters('the_content', $content);
        $content = str_replace(']]>', ']]>', $content);
        echo substr($content,0,[COLOR=Red]300[/COLOR]);
    ?>&hellip; <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">Read more &raquo;</a></p>
    Angka 300 yg di merahin adalah jumlah karakter yg ditampilkan sebelum Read more, ganti sesuai selera :shakehands:
     
    mqhidayat and xtmxady like this.
  7. xtmxady

    xtmxady Super Hero

    Joined:
    Dec 13, 2009
    Messages:
    3,854
    Likes Received:
    74
    Location:
    Tarakan BAIS \m/
    @ GI : manteb om, entar tak coba :senyum:
     
  8. waskitho

    waskitho Ads.id Pro

    Joined:
    Jun 11, 2009
    Messages:
    299
    Likes Received:
    24
    Location:
    jogja
    bedanya ama the_excerpt bawaan wordpress apa?
     
  9. gembel-intelek

    gembel-intelek Lurker

    Joined:
    Mar 29, 2009
    Messages:
    4,341
    Likes Received:
    907
    Location:
    New Coral

    kalo dah nyobain keduanya, tar tau bedanya :D

    --- Update ---

    setelah liat sigy-nya ngeri :swt2:

    ga ada bedanya ama
    Code:
    <?php the_excerpt(); ?>
    sepanjang functions.php

    ditambah


    Code:
    function new_excerpt_more($excerpt) {
        return ' <a href="'. get_permalink($post->ID) . '"> ...Read more &raquo;</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
     
  10. thevixi

    thevixi Super Hero

    Joined:
    Aug 29, 2009
    Messages:
    3,284
    Likes Received:
    150
    Location:
    Ditelapak Kaki Ibu
    om gi kalo yang di index php uda dirubah kek yang disni gimana?
    kan ini
    <?php the_content(); ?>
    uda diganti gini
    <?php the_excerpt(); ?>
    mohon petunjuk
     
  11. gembel-intelek

    gembel-intelek Lurker

    Joined:
    Mar 29, 2009
    Messages:
    4,341
    Likes Received:
    907
    Location:
    New Coral

    Buka functions.php

    tambahin kode ini dibawah
    <?php paling atas

    atau diatas

    ?> paling bawah

    Code:
    function new_excerpt_more($excerpt) {
        return ' <a href="'. get_permalink($post->ID) . '"> ...Read more &raquo;</a>';
    }
    add_filter('excerpt_more', 'new_excerpt_more');
     
  12. thevixi

    thevixi Super Hero

    Joined:
    Aug 29, 2009
    Messages:
    3,284
    Likes Received:
    150
    Location:
    Ditelapak Kaki Ibu
    ok om GI thanks
    btw cara ngilangin gambarnya gimana yah om?
    koq postingan ane yang ada gambarnya readmorenya ga bisa diklik alias ga ada linknya?:pusing:
    malah readmorenya guede banget om
    soalnya ane juga pake plugin advance excerpt
     
  13. gembel-intelek

    gembel-intelek Lurker

    Joined:
    Mar 29, 2009
    Messages:
    4,341
    Likes Received:
    907
    Location:
    New Coral

    yg mana? :pusing: coba image-nya dikasih thumbnail
     
    Last edited: Jun 19, 2010
  14. aminhidayat

    aminhidayat Super Hero

    Joined:
    Jul 24, 2008
    Messages:
    1,678
    Likes Received:
    76
    Location:
    tokopedia
    itu image nya ikut gan? (image dari self host dan dari url lain )
    btw thanks atas tutorialnya

     
  15. thevixi

    thevixi Super Hero

    Joined:
    Aug 29, 2009
    Messages:
    3,284
    Likes Received:
    150
    Location:
    Ditelapak Kaki Ibu
    imagenya tuh om nongol juga, ga bisa disembunyiin pake redamore,
    imagenya aku ambil dari url lain om:pusing:
    btw ngasih thumbnail gimana om?harus ngedit postingan satu2 gitu om?:pusing:
     
  16. cah bengak

    cah bengak Newbie

    Joined:
    Dec 9, 2009
    Messages:
    14
    Likes Received:
    0
    Location:
    MeccaNET
    mantaab.....:gembira:
     
  17. cah koplo

    cah koplo Super Hero

    Joined:
    Feb 2, 2010
    Messages:
    812
    Likes Received:
    3
    Location:
    di temani secangkir kopi
    makasih gan inponya:senyum:
     
  18. muklaz

    muklaz Newbie

    Joined:
    Jun 19, 2010
    Messages:
    22
    Likes Received:
    0
    Location:
    pemalang
    bukmak dulu. makasih sudah share infonya mas :senyum:
     
  19. matpeci

    matpeci Ads.id Pro

    Joined:
    Nov 15, 2009
    Messages:
    252
    Likes Received:
    9
    Location:
    Jakarta
    Wisssss mantap bener ini maeen an :gembira:

    Saya coba sesuai petunjuk langsung mantap tap..., tinggal 2 teknik lagi yang membuatku bertanya-tanya ;

    1. Bagaimana caranya supaya image yang nongol bisa "diatur" sesuka hati kita? kebetulan saya ekprimen di magazine theme. beda kolom beda image, ada yang ukuran imagenya 70x70 ada yang 150x150 dst.

    2. Bagaimana caranya supaya image itu bisa diklik yang mengarah ke permalink? (seperti kalau kita pakai plugin thumnail for excerpt, image-nya click-able)

    Thanks :kembang:
     
  20. mqhidayat

    mqhidayat Super Hero

    Joined:
    Sep 24, 2008
    Messages:
    1,289
    Likes Received:
    151
    Location:
    Ngalam
    klo mo ngilangin image, ato tag2 html yg lain pake post pertama thread ini.
    Ini yg jadi pembeda antara yg saia sharing dg yg di-share tmen2.

    tapi, asli seru. saia baru tahu script2 bwt kayak bginian dari thread ini.
     

Share This Page