Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Kupası
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

Nasıl Yapılır? WordPress’te Eklentiler Olmadan Küçük Resimlerle İlgili Yazılar

Editoryal Not: WPBeginner üzerindeki ortak bağlantılardan komisyon kazanıyoruz. Komisyonlar, editörlerimizin görüşlerini veya değerlendirmelerini etkilemez. Editoryal Süreç hakkında daha fazla bilgi edinin.

WordPress web sitenizde ilgili yazıların bir listesini görüntülemek istiyor ve bir eklenti yerine kod kullanmayı mı tercih ediyorsunuz?

Blogunuzu ziyaret edenler ilgilendikleri bir makaleyi okumayı bitirdiklerinde, ilgili gönderilerin bir listesini sunmak onların ilgisini çekecek ve okuyacak yeni içerik bulmalarına yardımcı olacaktır.

Bu makalede, WordPress ile ilgili yazıları eklenti gerektirmeden kod kullanarak nasıl görüntüleyeceğinizi göstereceğiz.

How to: Related Posts with Thumbnails in WordPress Without Plugins

WordPress’te Neden İlgili Yazıları Gösterelim?

WordPress blogunuz büyümeye başladığında, kullanıcıların aynı konudaki diğer yazıları bulması daha zor hale gelebilir.

Her blog gönderisinin sonunda ilgili içeriklerin bir listesini görüntülemek, ziyaretçilerinizi web sitenizde tutmanın ve sayfa görüntülemelerini artırmanın harika bir yoludur. Ayrıca, en iyi içeriğinizi insanların kolayca bulabileceği yerlerde göstererek en önemli sayfalarınızın görünürlüğünü artırmaya yardımcı olur.

Koda aşina değilseniz, ilgili gönderileri kod olmadan görüntüleyebilen birçok WordPress ilgili gönderi eklentisinden birini seçmeyi daha kolay bulacaksınız.

Ancak, bir eklenti kullanmadan ilgili gönderileri görüntüleyip görüntüleyemeyeceğinizi merak ettiyseniz, yalnızca kod kullanarak küçük resimlerle ilgili gönderiler oluşturmak için kullanabileceğiniz iki farklı algoritmayı paylaşacağız:

Not: İlgili her gönderide bir küçük resim göstermek istiyorsanız, önce bu gönderilere öne çıkan bir görsel eklediğinizden emin olun.

Yöntem 1: WordPress’te İlgili Yazıları Etiketlere Göre Gösterme

İlgili içeriği bulmanın etkili bir yolu, aynı etiketleri paylaşan diğer gönderileri aramaktır. Etiketler genellikle bir gönderide yer alan belirli ayrıntılara odaklanmak için kullanılır.

Bunu göz önünde bulundurarak, devam etmek ve birbirleriyle ilişkilendirmek istediğiniz gönderilere bazı ortak etiketler eklemek isteyebilirsiniz. Bunları WordPress editöründeki ‘Etiketler’ kutusuna girebilirsiniz.

The ‘Tags’ Settings Box in the WordPress Editor

Yazılarınıza etiketler ekledikten sonra yapmanız gereken bir sonraki şey, aşağıdaki kod parçacığını temanızın single.php şablonuna eklemektir.

Sitenize kod eklemek için yardıma ihtiyacınız varsa, web’deki parçacıkların WordPress’e nasıl yapıştırılacağına ilişkin kılavuzumuza bakın.

$orig_post = $post;
global $post;
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=>5, // Number of related posts that will be shown.
'ignore_sticky_posts'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
   
echo '<div id="relatedposts"><h3>Related Posts</h3><ul>';
   
while( $my_query->have_posts() ) {
$my_query->the_post(); ?>
   
<li><div class="relatedthumb"><a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><!--?php the_post_thumbnail(); ?--></a></div>
<div class="relatedcontent">
<h3><a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><!--?php the_title(); ?--></a></h3>
<!--?php the_time('M j, Y') ?-->
</div>
</li>
<!--?php }
echo '</ul--></ul></div>';
}
}
$post = $orig_post;
wp_reset_query();

Bu kod, bir sayfayla ilişkili etiketleri arar ve ardından benzer etiketlere sahip sayfaları getirmek için bir veritabanı sorgusu çalıştırır.

Kodu nereye yerleştirmelisiniz? Bu temanıza bağlıdır, ancak çoğu durumda kodu temanızın single.php şablonuna ana yazıdan sonra ve yorumlar bölümünün hemen üstüne yapıştırabilmeniz gerekir.

Demo sitemizde olduğu gibi Twenty Twenty-One temasını kullanıyorsanız, kodu yapıştırmak için iyi bir yer template-parts/content/content-single.php dosyasında başlıktan sonra ve <?php the_content(); ifadesinden hemen sonradır.

Related Content by Tags Preview

Bu, herhangi bir WordPress gönderisinde ilgili içeriği otomatik olarak görüntüleyecektir. Özel CSS ekleyerek ilgili gönderilerinizin stilini ve görünümünü temanızla eşleşecek şekilde değiştirmeniz gerekir.

Related Posts example

İpucu: Web sitenizi bozabilecek tema dosyalarınızı düzenlemek yerine, WPCode gibi bir kod parçacıkları eklentisi kullanmanızı öneririz.

WPCode, WordPress’e özel kod eklemeyi güvenli ve kolay hale getirir. Ayrıca, WordPress sitenizdeki belirli konumlara (örneğin bir yazıdan sonra) otomatik olarak kod parçacıkları eklemenizi ve çalıştırmanızı sağlayan ‘Ekleme’ seçenekleriyle birlikte gelir.

WPCode insertion options for custom code snippets

Daha fazla ayrıntı için WordPress’te özel kod ekleme kılavuzumuza bakın. Eklenti hakkında daha fazla bilgi edinmek için detaylı WPCode incelememize de göz atabilirsiniz.

Yöntem 2: WordPress’te Kategoriye Göre İlgili Yazıları Gösterme

İlgili içeriği görüntülemenin bir başka yolu da aynı kategorideki gönderileri listelemektir. Bu yöntemin avantajı, ilgili gönderiler listesinin neredeyse hiçbir zaman boş kalmamasıdır.

Yöntem 1’de olduğu gibi, temanızın single.php şablonuna veya WPCode gibi bir kod parçacıkları eklentisine bir kod parçacığı eklemeniz gerekir. Daha fazla ayrıntı için Yöntem 1’e ve WordPress’te özel kod ekleme kılavuzumuza bakın.

$orig_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;
$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 2, // Number of related posts that will be shown.
'ignore_sticky_posts'=>1
);
$my_query = new wp_query( $args );
if( $my_query->have_posts() ) {
echo '<div id="related_posts"><h3>Related Posts</h3><ul>';
while( $my_query->have_posts() ) {
$my_query->the_post();?>
   
<li><div class="relatedthumb"><a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><!--?php the_post_thumbnail(); ?--></a></div>
<div class="relatedcontent">
<h3><a href="<?php the_permalink()?>" rel="bookmark" title="<?php the_title(); ?>"><!--?php the_title(); ?--></a></h3>
<!--?php the_time('M j, Y') ?-->
</div>
</li>
<!--?php }
echo '</ul--></ul></div>';
}
}
$post = $orig_post;
wp_reset_query();

Artık her gönderinin altında ilgili içeriklerin bir listesini göreceksiniz.

İlgili sayfalarınızın stilini ve görünümünü değiştirmek istiyorsanız, temanızla eşleşmesi için özel CSS eklem eniz gerekecektir.

WordPress’te ilgili gönderileri görüntüleme hakkında daha fazla bilgi edinmek ister misiniz? İlgili gönderiler hakkındaki bu yararlı eğitimlere göz atın:

Umarız bu eğitim, WordPress’te eklentiler olmadan ilgili yazıları küçük resimlerle nasıl görüntüleyeceğinizi öğrenmenize yardımcı olmuştur. Ayrıca WordPress sitenize gelen ziyaretçileri nasıl takip edeceğinizi öğrenmek veya web sitenizi hızlandırmak için 24 ipucu listemize göz atmak isteyebilirsiniz.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Açıklama: İçeriğimiz okuyucu desteklidir. Bu, bazı bağlantılarımıza tıklarsanız komisyon kazanabileceğimiz anlamına gelir. WPBeginner'ın nasıl finanse edildiğini, neden önemli olduğunu ve nasıl destek olabileceğinizi görün. İşte editoryal sürecimiz.

Avatar

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

Ultimate WordPress Araç Kiti

Araç setimize ÜCRETSİZ erişim sağlayın - her profesyonelin sahip olması gereken WordPress ile ilgili ürün ve kaynaklardan oluşan bir koleksiyon!

Reader Interactions

183 yorumBir Cevap Bırakın

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. zioneyemedia says

    I do have a question on this: I’m wrestling on the code to capture posts from child categories versus parent categories. Any advice?

  3. dustinporchia says

    I’m trying to use the related posts by category and I noticed that you said the code has to come before the comments in the main loop. In my code I want the related posts to come after the comments in the loop. When I do this I notice my disqus comment plugin takes longer to load now. Is that because of an error with the comments or is that normal?

  4. subzerokh says

    please

    could someone help a newbie like me customize this script so it’ll display related post in an horizontal way?

    from left to right..

    instead of currently showing it from up to down, vertically…

    • zioneyemedia says

      Hey,

      How I did it is I replaced the and codes with my own html and css. The codes create lists for each post, and that is usually in a vertical fashion.

      ——————

      <a href="” rel=”bookmark” title=””> <a href="” rel=”bookmark” title=””>

      ——————

      I replaced the opening with and replaced the closing with as my html tags. Then I write my CSS to fit that specific div class needs on your website. For example, a sample pleft class could look like this:

      .pleft {float:left; padding:2px; margin:10px; width:278px; height:190px;}

      I use the float: selector on my CSS to move posts horizontally, and the margins and padding to give each post spacing within each other. I added in a specific width and height for additional examples.

      Hope this helps.

  5. gcog says

    I’ve got related tags for sure, but when I add the code I see nothing. Also, when I add your code to restrict to a custom post type, it gives me an error. I did change the post type to my specific post type.

  6. subzerokh says

    @wpbeginner hello

    thanks for your quick answer…

    but i’m a real novice at all you are saying..

    can you please give a litlle exemple?

    for making them horizontal as on your own blog?

    can get in touch by my mail: khiloc at gmail dot com

  7. wpbeginner says

    @subzerokh You would have to edit the styling. It is not that hard. Simply wrap each post in a div. Specify a width for that div and then set a float left property. Adjust the margins and such and you have it.

  8. subzerokh says

    hello all!! thanks for this wonderfull script!!

    It’s the only thing i found doing exactly what i wanted!!!

    But it’s just showing related post in vertical way (from up to down)

    I would like it to be shown from left to right (horizontally)

    How to do that please??

  9. xavpro says

    hey,

    great post! maybe you could help me:

    i have a auto thumb if none is defined,

    if ($thumb_array[‘thumb’] == ”) $thumb_array[‘thumb’] = ‘link to your default thumbnail image’;return $thumb_array;

    now my question is how to define a thumb for each category, which will be used if none is defined at post.

  10. AdnanAsif says

    Hi

    thanks for your great post..

    But any change to get posts by categories but not in ul and li and not in thumb..

    I mean full posts show in related posts..just like show on home page, with readmore link.

    thanks

    waiting your reply..

  11. AdnanAsif says

    Hi

    thanks for your great post..

    But any change to get posts by categories but not in ul and li and not in thumb..

    I mean full posts show in related posts..just like show on home page, with readmore link.

    thanks

    waiting your reply..

  12. jaffa says

    This is great, just what I have been looking for. I wonder though, how could I combine the two above and if there are no tags then it displays posts from the same category?

    Trying to figure this out but not getting very far yet

  13. nikbanks says

    Thanks for the code it worked but how do I style it. I’d like it to be 4 stories side by side like yours. It is listed one on top of another on my site and not listed like yours.

    • Editorial Staff says

      That is CSS. We are not using this code to show related stories. Second, i believe what you are talking about is featured stories on our sidebar. We have written another post about that in our site.

      Yönetici

  14. Coolguy says

    is ther a way to dispay the thumbs in related post without using featured images or post thumbs??
    i.e to use any image used in the post …

    • Editorial Staff says

      Yes, you can utilize the fallback techniques shared by other developers which pulls the first image from the post. But we recommend using the WordPress post thumbnails…

      Yönetici

  15. Adrian says

    Hi there…Just wanted to say that I’ve been building my wordpress website from the ground up and this code works perfectly for me using WP 3.1….All I need to do now is style the CSS and get some thumbnails happening for the posts. Thanks for your help with the code.

  16. Patricia says

    Hi, is there a way to exclude categories? I have two main categories where all the categories get assigned to. The main categories have sub-categories and I would like to show just related posts from the sub-categories.

    Is this possible, by excluding the id’s of the main categories?

    Thanks for your advice!

    BTW…love the code…and it works great!!!

  17. John says

    Just one question, is there a way to only pull tags from the same post type? Maybe using something like ‘post_type=videos’?

    • John says

      By the way, got this figured out as well:

      Just add it to the array:

      $args=array(
      ‘category__in’ => $category_ids,
      ‘post__not_in’ => array($post->ID),
      ‘posts_per_page’=> 2, // Number of related posts that will be shown.
      ‘caller_get_posts’=>1,
      ‘post_type’=>’videos’
      );

  18. marion says

    Hi,

    Thank you for this tutorial. I’m wondering though if there’s anyway the related products can be randomized? I’ve checked different products in the same category and the same related products were shown.

    Thanks

  19. John says

    I copied this code and put it in my single.php without changing a thing and nothing gets outputted. Anything wrong with my code? pastebin.com/kg0SkrAg

  20. James says

    This doesn’t bring up a thumbnail — there isn’t even a call for an image int eh code. I don’t see how anyone can get this to work.

  21. Roberto Silva says

    hey man, I love your blog!

    I have a question?

    Can you do the same trick but ” BY Author” ?

    showing the latest posts by author?

    you will save my life :-)

    Btw thanks for this website!

  22. Quinn says

    Thanks for this code! I’ve given it a try and it works somewhat.

    I can get it to give a listing of the related articles, a huge benefit.

    But I can’t seem to get any images to show up.

    The articles have images if this code scrapes.

    I also went in and created images for each post with the custom tag “relatedthumb”. But alas, still no images.

    Is there something else I need to do?

    Many thanks in advance!

    Quinn

  23. Sophie says

    I’m trying to modify his code in order to use it with categories within a custom post type. Can anyone help? I’m fairly new to php.

    Thanks!

  24. Heather Hill says

    HI!
    Thanks for this information! This is exactly what I was looking for.
    Is there a way to add an excerpt to this, along with the photo?

    Thanks again for your help!

  25. Omer Greenwald says

    Thanks for sharing. I’m using this code for a while now but it has a problem: when adding tags to a post, WP sorts them alphabetically regardless of the priority I added them. So this code displays related posts matching the first tag only which are less relevant sometimes.
    Maybe you have an idea how to prevent this auto sorting of tags by WordPress or any other solution?

  26. Liam says

    Great tutorial. Would someone mind showing me a working single.php with this code?

    I’m still learning php.

    Unfortunately
    Parse error: syntax error, unexpected T_ENDIF in C:\xampplite\htdocs\mock\wp-content\themes\scwd\single.php on line 76

  27. Vivek @ InfoEduTech says

    Thanks for this article. i am searching for lot of time to show the thumbnails with my article i am unable to perform this. i have tried many wordpress plugin but couldn’t done this. hope this might help me out

Bir Cevap Bırakın

Yorum bırakmayı seçtiğiniz için teşekkür ederiz. Lütfen tüm yorumların yorum poli̇ti̇kasi uyarınca denetlendiğini ve e-posta adresinizin yayımlanmayacağını unutmayın. Ad alanında anahtar kelime KULLANMAYIN. Kişisel ve anlamlı bir sohbet edelim.