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. kabir bairwa says

    I was trying to correct WordPress-related posts but it was not happening when I saw this code and I used this code in my WordPressfile so now my WordPress-related posts coming properly

  3. Jennifer says

    Is there a way to have related post based on the post title. I do not have tags and my categories really don’t do the trick since there is no distinction between them.

    This would be of great help if you had a code to show related content based on the post title.

    • WPBeginner Support says

      Thank you for your feedback, this article should currently be using the php version everywhere :)

      Yönetici

  4. Motahar Hossain says

    Thank you for your nice post.

    Here “ignore_sticky_posts” should be used instead of “caller_get_posts”. Because “caller_get_posts” is deprecated.

    • WPBeginner Support says

      This method limits the posts to the category the post is in. To limit the categories you would need to create an if statement to exclude certain categories.

      Yönetici

  5. Greg says

    Is it possible where there are more than X related posts by category that are related that you can randomise say 3 posts?

    • WPBeginner Support says

      While it is possible, it would require adding far more to this, you may want to look into a plugin for that type of customization.

      Yönetici

  6. Luis says

    I found a way to make the smaller thumbnails, but it shows them in a column and not horizontally. How can this be modified?

  7. Luis says

    The script is working well. The only problem I have is that the thumb-nails are very large. Would there be some way to make them smaller?

  8. Ana says

    how to do for create a shortcode for this code, I created the function but I do not know how to return the print to the page.

  9. Mike says

    Hello,
    I’m a beginner in WorldPress.
    I’d like to show Related Posts.
    In the main menu I have Category A, and in Category A – Subcategories A, B and C. The posts are in Category A, but they can also be present in all 3 Subcategories.
    When choosing one of the Related Posts something goes wrong and the posts from the initially chosen Subcategory don’t show correct anymore.

  10. pawan singh says

    Hi Admin, Very informative article. I like your site because of simplicity and straightforwardness. All articles are to the point but when it comes to sharing the knowledge of code you become too technical. Just ignore the fact that much of the visitors are not coding expert. Wouldn’t it be much better if you just add 2or 3 more lines in your explanation to make it complete and easily understandable to all. Anyway, great article But I want to know which code or plugin is Wpbeginner using?

  11. Tracy says

    what really sucks about your articles is you never actually say HOW to do something. It’s all well and good to tell me to put code into my single.php, but as a beginner I don’t know what that is or where to find it. You might want to think about putting this kind of critical information into your articles instead of assuming we know what it means, or that we have surfed every one of your articles to figure it out.

  12. Rose says

    Thanks for the great post, very useful. I came across an error in the code so wanted to share in hope it may be useful for others in the future. The error was:

    WP_Query was called with an argument that is deprecated since version 3.1.0! “caller_get_posts” is deprecated. Use “ignore_sticky_posts” instead.

    So I simply replaced it and it worked fine. I am also using namespacing so I needed to change WP_Query to \WP_Query plus I changed the order of the below:

    global $post;
    $orig_post = $post;

    Thanks again
    Rose

  13. sanjeev Kumar says

    sir
    I am using the code of categories working properly but one thing is when on home page same category of 2 or 3 post then the link show balack but i want to show to show category which is next post

  14. Luan says

    Hi,

    Thanks for your post. I added the code in content-single.php and it worked. However, it displays as 1 column not 3 columns like your example. Could you please help me on this? I want my related posts to be displayed in 1 row, 3 columns. Thanks so much.

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.