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

Her WordPress Gönderisine Farklı Stil Verme

Web sitenizdeki her WordPress gönderisine farklı bir stil vermek mi istiyorsunuz?

Yapışkan gönderileri özel bir arka planla vurgulayan veya her kategori gönderisini benzersiz bir görünümle şekillendiren bazı web sitelerine rastlamış olabilirsiniz. Farklı içerik türlerini yansıtmak ve kullanıcılar için görsel olarak çekici bir deneyim oluşturmak için siz de bunu yapabilirsiniz.

Bu makalede, her WordPress gönderisini farklı şekilde nasıl kolayca şekillendirebileceğinizi göstereceğiz.

Style Each WordPress Post Differently

Not: Bu eğitim WordPress’e özel CSS eklemenizi gerektirmektedir. Ayrıca Inspect aracını kullanabilmeniz ve bazı temel CSS bilgilerine sahip olmanız gerekecektir, bu nedenle tamamen yeni başlayanlar için uygun olmayabilir.

Her WordPress Gönderisini Farklı Şekillendirmenin Artıları ve Eksileri

Bir WordPress blogunuz varsa, her bir yazıyı farklı şekilde şekillendirmek, farklı renklerin farklı içerik kategorileri veya türleriyle ilişkilendirildiği benzersiz bir görsel deneyim oluşturabilir.

Örneğin, web sitenizdeki tüm liste yazıları, blog gönderileri ve nasıl yapılır eğitimleri için farklı bir arka plan rengi kullanabilirsiniz. Bu, kullanıcıların dikkatini anında çekebilir ve etkileşimi artırabilir.

Bunu yapmanın bazı önemli dezavantajları da olabileceğini unutmayın. Örneğin, her WordPress gönderisinin tasarımını düzenli olarak sürdürmeniz gerekecektir ki bu da zaman alıcı olabilir.

Ayrıca, tutarsız bir kullanıcı deneyimi sağlayabilir ve marka kimliğinize yardımcı olmaz. Bunun nedeni, işletmenizin imajını oluşturmak için web sitenizde aynı renkleri kullanmanız gerektiğidir.

Eğer yeni başlayan biriyseniz, her bir yazıyı şekillendirmek için özel CSS eklemek de zor olabilir. Bunu söyledikten sonra, her bir WordPress gönderisini nasıl kolayca farklı şekillendirebileceğinizi görelim.

WordPress’te Bireysel Yazılara Nasıl Stil Verilir?

WordPress, web sitenizdeki çeşitli öğelere varsayılan CSS sınıfları ekler. Temalar, WordPress’e gönderiler için bu varsayılan CSS sınıflarını nereye ekleyeceğini söylemek için post_class() adlı temel bir WordPress işlevi kullanır.

Web sitenizi ziyaret eder ve tarayıcınızdaki İnceleme aracını kullanırsanız, her gönderi için eklenen bu sınıfları görebilirsiniz.

Use the Inspect tool to view the CSS classes

Aşağıda, kullanıcının hangi sayfayı görüntülediğine bağlı olarak varsayılan olarak eklenen CSS sınıfları verilmiştir:

  • .post-id
  • .post
  • .attachment
  • .sticky
  • .hentry (hAtom mikroformat sayfaları)
  • .category-ID
  • .category-name
  • .tag-name
  • .format-{format-name}
  • .type-{post-type-name}
  • .has-post-thumbnail

Örnek bir çıktı şu şekilde görünebilir:

<article id="post-412" class="post-412 post type-post status-publish format-standard hentry category-news">

Bu ilgili CSS sınıflarını veya kimliklerini kullanarak her bir WordPress gönderisini farklı şekilde şekillendirebilirsiniz. Bunu yapmak için öncelikle tek bir yazının yazı kimliğini bulmanız gerekir.

Bunun için WordPress kontrol panelinden Yazılar ” Tüm Yazı lar sayfasını ziyaret etmeli ve farenizi bir yazının üzerine getirmelisiniz.

Şimdi ekranınızın sol alt köşesinde bir gönderi düzenleme URL’si görünecektir. Burada, ‘post=’ ve ‘&action’ arasındaki sayıya bakarak gönderi kimliğini bulabilirsiniz.

Aşağıdaki örnekte gönderi kimliği 25’tir.

Bunu yaptıktan sonra, CSS sınıfını özel kodla birlikte tema dosyalarınıza veya tema özelleştiricisine eklemeniz gerekir. Ancak bu riskli olabilir ve tek bir hatayla sitenizi bozabilir.

Bu yüzden bunun yerine WPCode kullanmanızı öneririz. En iyi WordPress kod parçacıkları eklentisidir ve sitenize özel kod eklemenin en güvenli yoludur.

Öncelikle ücretsiz WPCode eklentisini yüklemeniz ve etkinleştirmeniz gerekir. Ayrıntılar için bir WordPress eklentisinin nasıl kurulacağına ilişkin başlangıç kılavuzumuza bakın.

Etkinleştirmenin ardından, WordPress kontrol panelinden Kod Parçacıkları ” + Parçacık Ekle sayfasını ziyaret edin. Burada, ‘Özel Kodunuzu Ekleyin (Yeni Snippet)’ seçeneğinin altındaki ‘Snippet Kullan’ düğmesine tıklayın.

addnewsnippet

Bu sizi kod parçacığınız için bir ad ekleyerek başlayabileceğiniz ‘Özel Snippet Oluştur’ sayfasına götürecektir. Bundan sonra, sağdaki açılır menüden kod türü olarak ‘CSS Snippet’i seçin.

Ardından, gönderinizin CSS sınıfını ve kimliğini ‘Kod Önizleme’ kutusuna aşağıdaki gibi eklemelisiniz:

.post-13 { }

Bundan sonra, yazınızı şekillendirmek için parantezler arasına her türlü özel CSS kodunu ekleyebilirsiniz.

Add the individual post ID in the Code Preview box

Örneğin, tek bir gönderinin arka plan rengini değiştirmek istiyorsanız, aşağıdaki özel CSS kodunu ekleyebilirsiniz. Bu koddaki gönderi kimliğini kendi kimliğinizle değiştirmeniz gerektiğini unutmayın. Bunun .post-13 olduğu yerde sizinki .post-23873 olabilir.

Arka plan renginin onaltılık kodunu da istediğiniz herhangi bir renkle değiştirebilirsiniz:

.post-13 {
background-color: #FF0303;
color:#FFFFFF;
}

Ardından, üstteki ‘Etkin Değil’ anahtarını ‘Etkin’ olarak değiştirin ve ayarlarınızı kaydetmek için ‘Snippet’i Kaydet’ düğmesine tıklayın.

Özel CSS kodu artık snippet etkinleştirildikten sonra tek tek gönderinizde otomatik olarak yürütülecektir.

Activate the CSS code snippet for the individual post

Devam edin ve değişiklikleri gerçek zamanlı olarak görmek için WordPress blog gönderinizi ziyaret edin.

Metin seçim rengini, metin rengini, dahili bağlantı rengini ve çok daha fazlasını değiştirmek için ‘Kod Önizleme’ kutusuna başka özel CSS kod parçacıkları da ekleyebilirsiniz.

Background color preview for an individual post

Daha fazla bilgi için WordPress’te renklerin nasıl özelleştirileceğine ilişkin başlangıç kılavuzumuza bakın.

Belirli Bir Kategorideki Gönderilere Stil Verme

Belirli bir kategoriye ait tüm gönderilere stil vermek istiyorsanız, bunu WPCode ile de yapabilirsiniz.

Code Snippets ” + Add Sn ippet sayfasını ziyaret etmeli ve ‘Add Your Custom Code (New Snippet)’ seçeneğini seçmelisiniz.

Ardından, yeni sayfaya bir kod parçacığı adı ekleyin ve kod türü olarak ‘CSS Snippet’i seçin. Bundan sonra, kod önizleme kutusuna aşağıdaki gibi belirli bir kategorinin CSS sınıfını yazın ve tire işaretinden sonra kategorinin kalıcı bağlantı slug ‘ını kullanın:

.category-books { }

Bunu yaptıktan sonra, farklı kategorilerdeki tüm gönderilere uygulamak için kutuya herhangi bir özel CSS snippet’i ekleyebilirsiniz.

Add the category CSS class and name in the code preview box

Örneğin, belirli bir kategorideki tüm gönderiler için yazı tipi boyutunu ve stilini değiştirmek istiyorsanız, aşağıdaki kod parçacığını kullanabilirsiniz. Sadece kategori adını web sitenize göre değiştirmeyi unutmayın.

category-books {
    font-size: 18px;
    font-style: italic;
}

Ardından, üstteki ‘Etkin Değil’ anahtarını ‘Etkin’ olarak değiştirin.

Ardından, devam edin ve ayarlarınızı kaydetmek için ‘Snippet’i Kaydet’ düğmesine tıklayın.

Preview of all the styled posts in a specific category

CSS kodu ile uygulanan değişiklikleri görmek için artık belirli bir kategorideki tüm gönderileri ziyaret edebilirsiniz.

Demo sitemizde bu şekilde görünüyordu.

Preview of all the styled posts in a specific category

Gönderileri Yazara Göre Farklı Şekillendirme

the_posts() işlevi tarafından oluşturulan varsayılan CSS sınıfları, yazar adını bir CSS sınıfı olarak içermez.

Her bir gönderinin stilini yazara göre özelleştirmek istiyorsanız, öncelikle yazarın adını bir CSS sınıfı olarak eklemeniz gerekir.

Bunu WPCode ile yapmak için ‘Özel Kodunuzu Ekleyin (Yeni Snippet)’ seçeneğini seçin.

Bu sizi bir kod parçacığı adı eklemeniz ve kod türü olarak ‘PHP Snippet’ seçmeniz gereken ‘Özel Snippet Oluştur’ sayfasına götürecektir.

Bundan sonra, aşağıdaki özel kodu ‘Kod Önizleme’ kutusuna ekleyin ve ‘user_nicename’ yerine yazarın adını yazın.

$author = get_the_author_meta('user_nicename'); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( $author );

Son olarak, ‘Etkin Değil’ anahtarını ‘Etkin’ olarak değiştirin ve ayarlarınızı kaydetmek için ‘Snippet’i Kaydet’ düğmesine tıklayın.

Bu şekilde görünmelidir.

Add the author's name as a CSS class

Bu kod şimdi kullanıcının nicename’ini bir CSS sınıfı olarak ekleyecektir. Nicename, WordPress tarafından kullanılan URL dostu bir addır. Boşluk içermez ve tüm karakterler küçük harfle yazılır, bu da onu bir CSS sınıfı olarak kullanmak için mükemmel hale getirir.

Şimdi Code Snippets ” + Add Snippet sayfasını tekrar ziyaret etmeli ve ‘Add Your Custom Code (New Snippet)’ seçeneğini seçmelisiniz. Bir sonraki ekranda, özel kodunuz için bir ad ekleyin ve sağdaki açılır menüden kod türü olarak ‘CSS Snippet’i seçin.

Daha sonra belirli yazarın adını ‘Kod Önizleme’ kutusuna aşağıdaki gibi ekleyebilirsiniz:

.sarahclare

Bundan sonra, arka plan rengini, kenarlık boyutunu, metin rengini ve daha fazlasını değiştirmek için özel CSS kodunu ekleyebilirsiniz.

Add the author's name in the code preview box

Bir yazarın gönderilerinin arka plan rengini değiştirmek ve içerik alanına bir kenarlık eklemek için aşağıdaki kodu kullanabilirsiniz.

.sarahclare {
background-color:#EEE;
border:1px solid #CCC;
}

İşiniz bittiğinde, en üstteki ‘Snippet’i Kaydet’ düğmesine tıklayın.

Ardından, ‘Etkin Değil’ anahtarını ‘Etkin’ olarak değiştirin.

Activate CSS snippet to style a specific author's posts

Özel kod, etkinleştirme üzerine otomatik olarak yürütülecektir.

Artık değişiklikleri görmek için belirli bir yazarın gönderisini ziyaret edebilirsiniz.

Preview of a specific author's styled posts

Yorum Sayısını Kullanarak Gönderileri Popülerliğe Göre Stilize Etme

Bazen yorum sayılarına dayanan popüler gönderi widget‘larına sahip siteler görmüş olabilirsiniz. Bu örnekte, yorum sayısını kullanarak gönderileri nasıl farklı şekillendirebileceğinizi göstereceğiz.

Öncelikle yorum sayısını almamız ve bununla bir sınıf ilişkilendirmemiz gerekiyor.

Yorum sayısını almak için aşağıdaki kodu tema dosyalarınıza eklemeniz gerekecek veya WPCode gibi bir kod parçacıkları eklentisi kullanabilirsiniz.

WPCode’da ‘Özel Snippet Oluştur’ sayfasını başlatmak için ‘Özel Kodunuzu Ekleyin (Yeni Snippet)’ seçeneğini seçmeniz yeterlidir.

Burada, Kod Türü olarak ‘PHP Snippet’i seçin ve ardından aşağıdaki kodu kopyalayıp Kod Önizleme kutusuna yapıştırın:

<?php 
    $postid = get_the_ID();
    $total_comment_count = wp_count_comments($postid);
        $my_comment_count = $total_comment_count->approved;
    if ($my_comment_count <10) {
        $my_comment_count = 'new';
    } elseif ($my_comment_count >= 10 && $my_comment_count <20) {
        $my_comment_count = 'emerging';
    } elseif ($my_comment_count >= 20) {
        $my_comment_count = 'popular';
    }
?>

Bundan sonra, ‘Snippet’i Kaydet’ düğmesine tıklayın ve ayarlarınızı kaydetmek için ‘Etkin Değil’ anahtarını ‘Etkin’ olarak değiştirin.

Bu kod, görüntülenen gönderi için yorum sayısını kontrol eder ve bu sayıya göre bir değer atar. Örneğin, 10’dan az yorum içeren gönderiler yeni olarak adlandırılan bir sınıf alır, 20’den azı gelişmekte olan olarak adlandırılır ve 20’den fazla yorum içeren her şey popülerdir.

Add the comment count code snippet

Şimdi, yorum sayısını post_class fonksiyonuna bir CSS sınıfı olarak eklemelisiniz. Bunu yapmak için, ‘Özel Snippet Oluştur’ sayfasını tekrar açmanız ve açılır menüden ‘PHP Snippet’ seçeneğini seçmeniz gerekir.

Ardından, önizleme kutusuna aşağıdaki özel kodu ekleyin:

<article id="post-<?php the_ID(); ?>" <?php post_class( $my_comment_count ); ?>>

Bundan sonra, ‘Snippet’i Kaydet’ düğmesine tıklayın.

Artık ‘Etkin Değil’ anahtarını ‘Etkin’ olarak değiştirebilirsiniz.

Add comment count as CSS class

Bu, her gönderinin sahip olduğu yorum sayısına bağlı olarak tüm gönderilere yeni, gelişmekte olan ve popüler CSS sınıfları ekleyecektir. Artık her bir gönderiyi popülerliğine göre şekillendirmek için özel CSS ekleyebilirsiniz.

Örneğin, gönderilere gönderilen yorum sayısına göre farklı kenarlık renkleri eklemek için aşağıdaki kodu kullanabilirsiniz.

.new {border: 1px solid #FFFF00;}
.emerging {border: 1px dashed #FF9933;}
.popular {border: 1px dashed #CC0000;}

İşiniz bittiğinde, ayarlarınızı saklamak için ‘Snippet’i Kaydet’ düğmesine tıklamayı unutmayın.

Style posts based on popularity

Bonus: WordPress’te Her Yazı için Farklı Bir Kenar Çubuğu Görüntüleyin

Her bir yazıyı farklı şekilde şekillendirdikten sonra, her bir yazı için benzersiz bir kenar çubuğu da eklemek isteyebilirsiniz. Bu, kullanıcıların ilgilenebileceği o makaleyle ilgili belirli içerikleri sergilemenize olanak tanıyacaktır.

Örneğin, bir seyahat blog unuz varsa ve Florida’da gezilecek yerler hakkında bir blog yazısı yayınladıysanız, Florida seyahat paketlerini gösteren özel bir kenar çubuğu oluşturabilirsiniz. Alternatif olarak, düzenlediğiniz bir Florida gezisi için bir kayıt formu gösterebilirsiniz.

Her yazı için farklı bir kenar çubuğu görüntülemek için WordPress için en iyi sayfa oluşturucu eklentisi olan SeedProd‘u kullanabilirsiniz.

SeedProd website

Sürükle ve bırak arayüzü, 320’den fazla hazır şablonu ve e-posta pazarlama hizmetleriyle entegrasyonu sayesinde mükemmel bir seçim.

Eklenti etkinleştirildikten sonra, açılış sayfası tasarımınız olarak özel bir sayfa ve ardından kenar çubuğu içeren bir düzen seçebilirsiniz.

Choose a Layout with a Sidebar

Bundan sonra, iletişim formları, arşivler, eşantiyonlar, arama kutusu, yorumlar ve daha fazlası dahil olmak üzere seçtiğiniz blokları sol sütundan kolayca sürükleyip bırakabilirsiniz.

İşiniz bittiğinde, üstteki açılır menüden ‘Kaydet’ ve ‘Yayınla’ düğmelerine tıklayın. Artık bir WordPress yazısı veya sayfası için belirli bir kenar çubuğunu başarıyla tasarladınız.

Drag the Blocks You Wish to Use Right onto the Sidebar

Ayrıntılar için WordPress’te her yazı ve sayfa için farklı bir kenar çubuğunun nasıl görüntüleneceğine ilişkin eğitimimize bakın.

Umarız bu makale her bir WordPress gönderisini nasıl farklı biçimlendireceğinizi öğrenmenize yardımcı olmuştur. WordPress’te etiketlerin nasıl biçimlendirileceğine ilişkin başlangıç kılavuzumuza ve en çok aranan WordPress ipuçları, püf noktaları ve hack‘leri listemize de 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

54 yorumBir Cevap Bırakın

  1. Syed Balkhi

    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. Rafael

    Nice article. I guess I could use something like this to check the category of a post and place a custom CSS to change the style of part of the website according to the category, right?

    I’m looking to set different colors only to the background of the Title of the Post for each Category in a Blog.

  3. Kany

    Hi, great article. How to custom css style latest blog news? Just the latest one, any idea? Tnx.

    • WPBeginner Support

      Your theme would need to add something that can be targeted by CSS, at the moment we do not have a recommended method for adding that.

      Yönetici

  4. Les

    Great article. I wanted to set the default Font size per category and followed the instruction by adding the code to the Style.css file but when I added a new post the font was the old size. See code? What am I missing?

    /* Begin Additional CSS Styles */
    .art-blockheader .t, .art-vmenublockheader .t {white-space: nowrap;}
    .desktop .art-nav-inner{width: 1200px!important;}

    .category-firstg {
    font-size: 18px;
    font-style: bold;
    }
    /* End Additional CSS Styles */

  5. William D

    Great article, thank you very much. Could the read more button color/text color also be changed in a similar manner? Something (I probably did) has changed my buttons in a very unpleasant way and I’m having a heck of a time trying to figure out how to make them pleasant again.

    Thanks in advance for any help you might provide!

  6. Matus

    Great tutorial. Simple and clear explanation.

  7. Neon Emmanuel

    Hello, if i include this in single.php it echo back the current post title, but works fine in index.php, any suggestion to this?

  8. MayMyatKhine

    Hello,Please send to me the new event to use the wordpress.

  9. marisa

    This is a great article but I’m having trouble with placing
    ID, ‘post-class’); ?>

    Where exactly in the loop do I put it? I am using underscore.me with foundation 5 and my new class isn’t appearing.

  10. Nadeem

    Thanx alot bro..its very helpful

  11. RW

    yet another bookmark! great post! thank you…

  12. Payal

    Very informative, thank you. I’ve bookmarked this page.

    I also have a question: What if I wanted to style the first (latest) post differently — so that the post displayed at the top of my index page shows up differently?

  13. James

    Hey there, I’m struggling with this atm..

    My post loop doesnt seem to have a post_class function so I cant figure out where to place the above code…

    This is the loop I use for posts, where would I place the above code? Or how could I get custom fields to work using this?

  14. Jon Fuller

    Hello, I am quite new to making WordPress themes and I am looking for a way to display each post in a box of its own which is seperated by a margin top and bottom. Please explain how this is possible.

    Thanks

    • Editorial Staff

      By default each post is inside its own div element. You just have to use CSS to add margin-top and bottom.

      Yönetici

  15. Shaun

    Curious, how could this be applied to adding a CSS class to only posts posted that have the same “meta value” or “meta value number”?

    Thanks for the great tutorial by the way!
    Best

    • Editorial Staff

      We showed how to do it with custom fields, but that’s being done by key. But if you have the same key with multiple values, then you should get_post_custom_values function.

      Yönetici

  16. Em

    Just found this post and it is great, clear, succinct and spot on, many thanks

  17. Jim

    I would like to do something where post one gets the class “1”, post two gets “2” post three gets “3”, and then it repeats this order, so post four gets “1” again.

    Any tips? it’s just repeating three different classes every three posts.

  18. Brit

    What I’m trying to do specifically is just make it so when someone lands on my blog, that the thumbnail (which is just a circle with the post title) is a different color for ONLY the most recent post. I’m at a loss of how to make this happen. Everything I’ve found is category or order specific. Thoughts?

    • Editorial Staff

      Brit, you would have to use the last method “Super Loop”. That is probably the only way of doing it because all what you would do is on the first post, you add a unique class such as “first-post” , and then style that using your CSS file.

      Yönetici

  19. Jayaseelan Arumugam

    It is very Nice and useful post. Especially I like the way to Style Posts based on Custom Fields. Thanks.

  20. Kathleen

    Thanks for this great article! It’s exactly what I searched for and so much helpful! :)

  21. dina

    How do I add unique class to the 3rd, 6th, 9th, and 12nd posts in super loop. Thanks!

  22. vajrasar

    Well, that is a very good piece. I got what you said, but can you shed some light on how am gonna implement this on my Genesis driven News Child theme, as I am supposed to do all this with function.php

    I would like to style category specific posts differently. Thanks a lot for this piece. very informative.

    • Editorial Staff

      So if you are just using the post class method, then Genesis has the field under their Layout settings for each post. You can enter a custom class and style it that way. The rest can get pretty complicated depending on all the hooks and such. We don’t necessary do genesis specific articles here.

      Yönetici

  23. jim

    What do you mean index.php in the loop. which index.php. Mine has nothing like yours. This is the 10th post I’ve read where no one has explained this basic concept properly. And what about the CSS. Last 10 posts didn’t explain that either. Internet is getting worse and worse.

    • Editorial Staff

      Hey Jim,

      Every WordPress theme does things differently. The concept of loop is pretty well explained in the WordPress Codex. It requires a simple google search: Loop WordPress which will take you to: http://codex.wordpress.org/The_Loop

      Because every theme varies, some utilize a separate loop.php file others are child themes which don’t even have index.php files. It is really hard to explain all of those concepts. When we put tutorials in a theme category, we expect the users to have a fair knowledge of how WordPress themes work (even if you don’t know PHP).

      Yönetici

  24. Haider E Karrar

    I think you should be using filters instead in combination with the template tags here http://codex.wordpress.org/Conditional_Tags

    For example

    function my_post_css_filters($content) {
    if(is_category(…))
    return ” $content “;
    else if (something else)
    ….

    }

    add_filter(‘the_content’, ‘my_post_css_filters’, 1) — (priority 1, not sure what else it may affect).

  25. Hossein

    Hi..

    How i can wrap every 4 posts in a div ?

  26. gashface

    Nevermind got that working, but NOW it doesn’t style each post differently, it just styles them all according to the first post author it finds?

  27. gashface

    Is there a way to specificy a tag like H2 is styled by author I am trying .username h2{} for example but it won’t work?

  28. gashface

    This doesn’t show the author with me just a blank space, pasted your exact code, any ideas? posts made by admin and are private, does that make a difference?

    • wpbeginner

      @gashface not it doesn’t make a difference whether the post is private or public… If it is returning a white page, then you are pasting the code in a wrong place.

      • gashface

        I realised it was because I was putting the code before the call to the loop, I thought you meant before the if have posts etc.. when it needs to go after that, thanks for the heads up

  29. KimeeDoherty

    This was a little helpful, but I am still lost :( Not sure how to include the loop file in order to override the template. You started the <div> tag but not ended them, what’s inside the div? I’m lost :(

  30. kristelvdakker

    Thank you so much for this post! It has been very helpful.

  31. Stuart

    Hi, thanks for the ideas – especially the super loop – pleased to have got it working on my site.

    But I wonder, complete php beginner here, so is there a way to adapt the code so each subsequent page of posts doesn’t get the styling that posts 1, 2, 3, & 4 get on the first page.

    In other words, I only want the first four posts on the first page to look any different to the rest.

    Cheers,
    Stu

    • Editorial Staff

      Yes. You can use is_paged() conditional tag, so it only shows up on the first page, but not the others. You can also use is_home() … so only on the homepage.

      Yönetici

      • Stuart

        Cool – thank you. Looks like is_paged() is the one for me – but unfortunately, my novice abilities mean I’m struggling to work out how to integrate it in to the code.

  32. Michael

    If you wanted to use this approach to separate posts visually based on their published date. How would you go about it? For example: style the 5 posts published on the 1st with a black background, and then style the posts published on the 2nd with a red background? Thanks in advance!

    • Editorial Staff

      The best way to do this is using the superloop method. Where you use the counter variable to set the post class values.

      Yönetici

  33. Dale

    I am trying to style each authors name a different colour on our wordpress website and I have followed your code as below:

    Whilst this code is kind of working on my wordpress theme it is putting end quotation marks after class-2 but before the authors name so the class is being closed without the name in it. I only found this out by putting that php inside the body where you can see the full string.

    Does anyone have any ideas why this is happening?

    • Dale

      Sorry it stripped out the php I posted but here is the class output of styling my posts by the authors name. The author here is called admin, and as you can see the closing tag is before the author name admin.

      “post-395 post type-post hentry category-uncategorized class-1 class-2″admin

  34. Bec

    Great post! That info is awesome for adding those extra special custom features to your design.

  35. Adam W. Warner

    Indeed a great post, hats off! However, I couldn’t help but keep thinking about when it’s time to upgrade the theme you’re making all these custom edits to. I try to use the functions file whenever possible to avoid overwrites.

    I would think it would be better to roll these loop edits into a function. I know that with Parent Themes like Thematic, Hybrid, Genesis, etc…that it’s possible (and advisable) to filter the loop and thus add these changes.

    @Ken – Maybe your plugin would negate the need for any functions altogether?

    Anyway, just my two cents and congrats Syed and the team on your continuing excellence on this site!

  36. Azad Shaikh

    Very useful post indeed. Why don’t you publish some wordpress themes with your awesome ideas and functionality. I would be great success.

    Thanks!

  37. Ken

    Your article has giving me a few ideas on how to improve my plugin, thanks for that!

    I just wrote a plugin (Scripts n Styles) for adding CSS directly to the head element from the post/page editing screen. (Only admin users can do this though.) It’s not as robust (or rather, doesn’t address the same thing) as your solution because the CSS only appears on the single view, not in the lists (archives).

    I’m considering adding the functionality to include a class name into post_class, but via a meta box on the admin screen. Then, the admin would only have to add the css to his theme. (Or, perhaps a setting screen to facilitate this?)

    Anyway, the Super Loop seems useful for theming in general, I’ll have to include that in my next one!

  38. Connor Crosby

    Wow, that is a great post! Perfect timing since I am making a new WordPress theme :)

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.