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

WTA: Bikin Related Post + Thumbnail + Excerpt

Discussion in 'Wordpress' started by Uya Jelek, Mar 12, 2012.

Tags:
  1. Uya Jelek

    Uya Jelek Super Hero

    Joined:
    Jul 28, 2009
    Messages:
    847
    Likes Received:
    51
    Location:
    Tanah Grogot, Kaltim
    Ane mau bikin Related post yang ada Thumbnailnya & ada excerptnya tanpa plugin. Bijimane ya caranya? Ane udah ubek-ubek forum and segala macem tutorial tapi kok ya gag ada yang pas, gagal melulu. Mohon bantuannya master hehe..... O:-)
     
  2. gembel-intelek

    gembel-intelek Lurker

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

    tambahkan di functions.php

    PHP:
       //function buat excerpt, default 80 karakter
       
    function gb_sum ($limit 80){
           
    $src get_the_excerpt ();
           
    $sum explode (' '$src$limit);
           if (
    count ($sum) >= $limit) {
               
    array_pop ($sum);
               
    $sum implode (" "$sum) . '...';
           } else {
    $sum implode (" "$sum);}
           return 
    $sum;
       }
       
    //function buat thumbnail, diambil dari attachment
       
    function gb_thumb (){
           if (
    $thumbs get_children (array (
               
    'post_parent' => get_the_ID (),
               
    'post_type' => 'attachment',
               
    'numberposts' => 1,
               
    'post_status' => null,
               
    'post_mime_type' => 'image',
               ))) {
               foreach (
    $thumbs as $thumb){
                   
    $img wp_get_attachment_image ($thumb->ID);
                   
    $link get_permalink ($thumb->post_parent);
                   
    $html '<div class="alignleft">';
                   
    $html .= '<a href="' $link '">' $img '</a>';
                   
    $html .= '</div>';
                   return 
    $html;
               }
           }
       }
       
    // function buat related post
       
    function gb_related_posts ($limit 5){
           global 
    $post;
           
    $categories get_the_category ($post->ID);
           
    $querycats = array();
           
    $i 0;
           foreach (
    $categories as $category){
               
    $querycats[] = $category->cat_ID;
               
    $i++;
           }
           
    $querycats implode (","$querycats);
           
    $args = array (
               
    'post__not_in' => array($post->ID),
               
    'cat' => $querycats,
               
    'showposts' => $limit,
               
    'orderby' => 'rand',
               );
           
    query_posts ($args);
           if (
    have_posts ()) :
               
    $html '<div style="clear:both"></div>';
               
    $html .= '<div class = "related">';
               
    $html .= '<h3>Related Post</h3>';
               
    $html .= '<ul>';
               
    $i 1;
               while (
    have_posts ()) :
                   
    the_post ();
                   
    $html .= '<li>' gb_thumb ();
                   
    $html .= '<strong><a href = "' get_permalink ($post->ID) . '" title = "' get_the_title ($post->ID) . '">' get_the_title ($post->ID) . '</a></strong><br />';
                   
    $html .= gb_sum (30);
                   
    $html .= '</li>';
                   
    $i++;
               endwhile;
               
    $html .= '</ul></div>';
               echo 
    $html;endif;
           
    wp_reset_query ();
       }
    tambah di single.php biasanya di bawah <?php the_content();?>

    PHP:
    <?php gb_related_posts();?>
     
    paimin222 and Uya Jelek like this.
  3. Uya Jelek

    Uya Jelek Super Hero

    Joined:
    Jul 28, 2009
    Messages:
    847
    Likes Received:
    51
    Location:
    Tanah Grogot, Kaltim
    Berhasil gan, thanks O:-)
     
  4. Publicster

    Publicster Newbie

    Joined:
    Sep 1, 2011
    Messages:
    11
    Likes Received:
    0
    Location:
    Manado
    pake seo alrp kan enak gan... sekalian ada auto linknya... :D
     
  5. qurathun

    qurathun Ads.id Pro

    Joined:
    May 15, 2011
    Messages:
    372
    Likes Received:
    43
    pakai themenya mastah khalid tuwh...dah ada thumnailnya kok...
     
  6. Nedya Amrih Prakasa

    Nedya Amrih Prakasa Newbie

    Joined:
    Sep 19, 2012
    Messages:
    34
    Likes Received:
    0
    Location:
    Bogor
    ted artikelnya muncul kaya di xrompas yg di dalem konten gimana caranya ya mastah ???
     
  7. turtle

    turtle Hero

    Joined:
    Mar 13, 2010
    Messages:
    582
    Likes Received:
    134
    Location:
    Semarang, Indonesia
    Masukan gan.
    Jangan pake query_posts. Lebih baik pake WP_Query class.
    Alasannya bisa dibaca disini:
    _http://wordpress.stackexchange.com/questions/1753/when-should-you-use-wp-query-vs-query-posts-vs-get-posts

    Cek jawabannya Rarst.
    Rarst = keren!
     
  8. tikampung

    tikampung Ads.id Starter

    Joined:
    Dec 3, 2012
    Messages:
    69
    Likes Received:
    9
    Location:
    heaven
    di ane koq nggak work gan :(
     
  9. lightblue

    lightblue Ads.id Pro

    Joined:
    Jan 24, 2010
    Messages:
    330
    Likes Received:
    14
    Location:
    tangerang
    baca function2 di wiki wordpress gan, lengkap :D
    cma yg kurang contoh2 aja..
    ckck
     
  10. nurhafid

    nurhafid Newbie

    Joined:
    Dec 6, 2012
    Messages:
    25
    Likes Received:
    0
    bener gan, seo alrp sekarang tampilannya tambah keren, tapi kok webnya jadi loadingnya agak lama ya, (apa cuma perasaan ane . . . )
     

Share This Page