• Home
  • Tools
  • Sitemap
  • Blogroll
  • My Aggregator
  • Cek Pagerank
  • About

  • Membuat Related Post Wordpress Dengan PHP

    December 25th, 2009 Under Internet, Wordpress | 134 Comments

    Untuk menampilkan related post pada wordpress kebanyakan blogger, menggunakan plugin seperti wordpress related plugin, yarpp, related post by category dkk seperjuangannyalah. Namun setelah saya selidiki (ala) plugin-plugin ini lumayan banyak memakan resource pada server hostingan khususnya buat yang menggunakan paket shared hosting dan mempunya postingan yang lumayan banyak.

    Untuk menghindari akibat-akibat yang tidak diinginkan dan untuk mengoptimalisasikan engine wordpress , ada baiknya sebagai alternatif menggunakan kode php untuk meggantikan plugin-plugin tersebut. Secara mudahnya buka singel.php pada theme yang anda gunakan dan tambahkan kode php berikut. (Sebelumnya Backup dulu file single.php anda).

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    <?php
    $this_post = $post;
    $category = get_the_category(); $category = $category[0]; $category = $category->cat_ID;
    $posts = get_posts('numberposts=6&offset=0&orderby=post_date&order=DESC&category='.$category);
    $count = 0;
    foreach ( $posts as $post )
    {
    if ( $post->ID == $this_post->ID || $count == 5)  <!-- banyak  related post yang ditampilkan -->
    {
    unset($posts[$count]);
    }
    else
    {
    $count ++;
    }
    }
    ?>
    <?php if ( $posts ) : ?>
    <div>
    <strong>Related Posts</strong> <!-- Judul, bisa diganti -->
    <ul>
    <?php foreach ( $posts as $post ) : ?>
    <li><a href="<?php the_permalink() ?>" title="<?php echo trim(str_replace("n"," ",preg_replace('#<[^>]*?>#si','',get_the_excerpt()))) ?>"><?php if ( get_the_title() ){ the_title(); }else{ echo "Untitled"; } ?></a></li>
    <?php endforeach // $posts as $post ?>
    </ul>
    </div>
    <?php endif // $posts ?>
    <?php
    $post = $this_post;
    unset($this_post);
    ?>
    1
    2
    3
    4
    5
    6
    7
    <?php the_content(__('')); ?>

    -->pastekan kira-kira disini,

    sesuaikan saja dengan theme yang anda gunakan

    <divclass="meta-footer">

    Kode php tersebut akan menampilkan 5 postingan yang terkait, sesuai dengan kategori postingan anda. Jika anda menggunakan kode php untuk melihat request query pada database wordpress, lihat saja perbandingan antara menggunakan plugin dan kode php.



    You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

    134 Responses to 'Membuat Related Post Wordpress Dengan PHP'

    1. feto December 30, 2009 at 6:28 pm
      feto
    2. rio2000 December 31, 2009 at 4:09 pm
      rio2000
    3. Pai January 1, 2010 at 9:03 am
      Pai
    4. Hanif Ilham M January 8, 2010 at 9:31 am
      Hanif Ilham M
    5. Satria Yudha February 1, 2010 at 11:18 am
      Satria Yudha
    6. Dunia Hape February 10, 2010 at 3:37 pm
      Dunia Hape
    7. SEO Haram February 21, 2010 at 5:19 pm
      SEO Haram

    Leave a Reply

    :hehe: :hore: :jedug: :love: :matabelo: :mikir: :hiks: :ngacir: :ngakak: :nyerah: :plis: :puyeng: :sikut: :sip:

    Need Another Emo..??