Burada, WPBeginner’da, kendi özel arşiv sayfamız var. Ancak birçok WordPress sitesi için tam bir sayfaya ihtiyacınız yoktur. Bazen okuyucuların eski içeriklerinizi bulmasına yardımcı olmak için tek ihtiyacınız olan kenar çubuğunuzdaki iyi düzenlenmiş bir arşiv bölümüdür.
Buradaki zorluk, varsayılan WordPress arşiv görüntüsünün kenar çubuğunuzda dağınık ve bunaltıcı görünebilmesidir. Bu durumda ziyaretçilerin tıklama ve eski yazılarınızı keşfetme olasılığı azalır.
Yıllar boyunca birçok farklı arşiv düzenini test ettik ve okuyucuların daha fazlasını keşfetmek istemesini sağlayan şeyin ne olduğunu tam olarak biliyoruz. İyi düzenlenmiş bir arşiv bölümü, ziyaretçileri sitenizde daha uzun süre tutabilir ve tam olarak aradıklarını bulmalarına yardımcı olabilir.
Bu kılavuzda, WordPress arşiv ekranınızı özelleştirmenin kanıtlanmış birkaç yolunu göstereceğiz. İster temiz bir açılır menü ister yıl yıl görünüm isteyin, size adım adım nasıl ayarlayacağınızı göstereceğiz.

WordPress Arşivlerinin Kenar Çubuğunuzdaki Görüntüsünü Neden Özelleştirmelisiniz?
WordPress arşivleri yazılarınızı tarihe göre otomatik olarak düzenleyerek ziyaretçilerin eski içerikleri bulmasını kolaylaştırır.
Birçok site sahibi WordPress sitelerine bir kenar çubuğu ekler ve geçmiş yazılara hızlı erişim için bu alana bir arşiv widget’ı dahil eder.
Bununla birlikte, kenar çubuğunuzda görüntülenen varsayılan arşivler genellikle çok uzun olabilir ve özellikle kapsamlı içeriğe sahip siteler için pek kullanıcı dostu olmayabilir. Aylar ve yıllardan oluşan basit bir liste, kullanıcılar için hızla bunaltıcı ve zevksiz hale gelebilir.
WordPress sitenizdeki kenar çubuğu arşivlerinizi özelleştirerek, arşiv listesinin çok uzun ve göz korkutucu olmasını önleyebilirsiniz.
İyi tasarlanmış bir arşiv bölümü, ziyaretçileri içeriğinizi daha fazla keşfetmeye teşvik ederek kullanıcı deneyimini de iyileştirebilir.
Bunu akılda tutarak, WordPress arşivlerinin kenar çubuğunuzda görüntülenmesini nasıl özelleştirebileceğinizi görelim:
- Option 1: Customize the Default Archives Block (No Plugin)
- Option 2: Create a Compact Archives Display
- Option 3: Display Archives in a Collapsible Menu
- Option 4: Limit the Number of Archive Months Displayed
- Option 5: Display Monthly and Yearly Archive Dropdown Menus
- Option 6: Display Monthly Archives Arranged by Year
💡 Uğraşmadan çarpıcı bir WordPress sitesi mi istiyorsunuz? Bırakın WPBeginner Pro Services ekibimiz sizin için halletsin. Uzman tasarımcılarımız, arşiv bölümü gibi özelliklerle tamamlanmış, ihtiyaçlarınıza göre uyarlanmış özel, profesyonel bir web sitesi oluşturabilir.
Seçenek 1: Varsayılan Arşiv Bloğunu Özelleştirin (Eklenti Yok)
Varsayılan WordPress arşiv bloğu veya widget’ı aslında arşivlerin nasıl görüneceğini özelleştirmek için seçeneklerle birlikte gelir.
Klasik bir tema kullanıyorsanız, blok tabanlı widget düzenleyicisini açmak için Görünüm “ Widget ‘lar bölümüne giderek bu ayarları görebilirsiniz.
Ardından, WordPress’teki kenar çubuğuna ‘Arşivler’ bloğunu eklemek için ‘+’ düğmesine tıklayın.

Sağ blok ayarları panelinde, arşivleri bir açılır menü olarak görüntüleme, arşiv etiketini gösterme ve her dönemde yayınlanan gönderi sayısını gösterme seçeneklerini göreceksiniz.
Arşivlerin yıl, ay, hafta veya güne göre görüntülenmesini de sağlayabilirsiniz.

Arşivlerin WordPress blogunuzda nasıl göründüğünden memnun olduğunuzda, ‘Güncelle’ye tıklayabilirsiniz.
İşte özelleştirdiğinizde blog kenar çubuğunuzda varsayılan WordPress arşivleri nasıl görünür:

Bir blok teması kullanıyorsanız, aynı ‘Arşivler’ bloğunu kullanabilir ve tam site düzenleyicisinde kenar çubuğu olan şablona ekleyebilirsiniz. Ayarlar tamamen aynıdır.
Daha fazla bilgi için WordPress tam site düzenleme kılavuzumuzu okuyabilirsiniz.
Bu varsayılan ayarlar temel bir blog için iyi olabilir. Ancak, yönetilecek çok fazla içeriğiniz varsa veya daha fazla özelleştirme seçeneği istiyorsanız bunlar yeterli değildir.
Arşiv ekranını özelleştirmek için daha fazla yol arıyorsanız, okumaya devam edin.
Seçenek 2: Kompakt Arşiv Ekranı Oluşturun
Arşiv listeniz çok uzadıysa, gönderilerinizi çok daha az alan kullanarak görüntüleyen kompakt bir arşiv oluşturabilirsiniz.
Compact Archives eklentisini yüklemeniz ve etkinleştirmeniz gerekir. Bu eklentiyi kendimiz geliştirdik ve 2.000’den fazla kullanıcı için iyi çalıştı.
Daha fazla yükleme talimatı için WordPress eklentisi yükleme hakkındaki adım adım kılavuzumuza bakın.
Eklenti etkin olduğunda, ‘WPBeginner’s Compact Archives’ bloğunu kullanarak kompakt arşivleri temanızın kenar çubuğuna ekleyebilirsiniz. Bu blok hem blok tabanlı widget düzenleyicisinde hem de tam site düzenleyicisinde kullanılabilir.

Daha sonra kompakt arşivlerin nasıl görüneceğini değiştirebilirsiniz.
Örneğin, ayın ilk baş harflerini, ayın ilk harfini veya ayın numarasını görüntülemeyi seçebilirsiniz.

Tamamlandığında, ‘Güncelle’ veya ‘Kaydet’e tıklamanız yeterlidir.
Eklenti hakkında daha fazla bilgi için WordPress’te kompakt arşivler oluşturma kılavuzumuza göz atın.

Seçenek 3: Arşivleri Katlanabilir Menüde Görüntüleme
Uzun arşiv listeleriyle başa çıkmanın bir başka yolu da blog yazılarını yayınladığınız yılların ve ayların daraltılabilir bir taslağını görüntülemektir.
Bunu yapmak için Collapsing Archives eklentisini yüklemeniz ve etkinleştirmeniz gerekir.
Eklenti etkin olduğunda, Görünüm ” Widget ‘lar sayfasını ziyaret etmeniz ve kenar çubuğunuza ‘Daralan Arşivler’ widget’ını eklemeniz gerekir.

Blok ayarları kenar çubuğunda, yıl veya ay içinde yayınlanan gönderi sayısını göstermeyi seçebilir, katlanabilir menüleri otomatik olarak genişletebilir, katlanabilir menü simgelerini değiştirebilir ve daha fazlasını yapabilirsiniz.
WordPress’te görüntülenen arşiv aylarının sayısının nasıl sınırlandırılacağına ilişkin kılavuzumuzdaki Yöntem 1’e bakarak daha fazla bilgi edinebilirsiniz.

Arşivlerin görüntülenme şeklinden memnun olduğunuzda, ‘Güncelle’ veya ‘Kaydet’e tıklayın.
İşte demo web sitemizde nasıl göründüğü:

Seçenek 4: Görüntülenen Arşiv Aylarının Sayısını Sınırlayın
Belki de varsayılan WordPress arşivlerinin görünümünü seviyorsunuzdur. Ancak tonlarca içeriğiniz varsa, her ayı veya yılı göstermek kenar çubuğunuzu çok uzun hale getirebilir. Arşiv listenizde görünen ay sayısını sınırlandırarak bunu düzeltebilirsiniz.
Bunu yapmak için WordPress temanızın dosyalarına özel kod eklemeniz gerekir.
Bunu daha önce yapmadıysanız, bu göz korkutucu görünebilir. Ancak endişelenmeyin, çünkü bunu güvenli bir şekilde yapmak için WPCode kullanabilirsiniz.
WPCode, WordPress’e özel kod parçacıkları eklemeyi ve yönetmeyi kolaylaştıran bir kod parçacığı eklentisidir. Bu şekilde, WordPress’e hangi kodu eklediğinizi takip edebilir ve kod çalışmazsa birkaç tıklamayla devre dışı bırakabilirsiniz.
Bu eğitim için WPCode’un ücretsiz sürümünü kullanabilirsiniz. Bununla birlikte, premium sürüm, teknik bilgi olmadan özel kod parçacıkları oluşturmanıza yardımcı olacak bir AI kod oluşturucu gibi birçok avantajla birlikte gelir.
Daha fazla bilgi için WPCode incelememize göz atabilirsiniz.
İlk olarak, WordPress yönetici panosuna WPCode’u yükleyelim. Biraz rehberliğe ihtiyacınız varsa, bir WordPress eklentisinin nasıl kurul acağına ilişkin adım adım kılavuzumuza göz atabilirsiniz.
Ardından, Kod Parçacıkları ” + Parçacık Ekle’ye gidin. ‘Özel Kodunuzu Ekleyin (Yeni Snippet)’ seçeneğini seçin ve ‘+ Özel Kod Ekle’ düğmesine tıklayın.

Şimdi, yeni kod parçacığınıza bir isim verin. ‘Görüntülenen Arşiv Aylarını Sınırla’ gibi basit bir şey olabilir.
Ardından, ‘Kod Türü’ için ‘PHP Snippet’i seçtiğinizden emin olun.

Devam edin ve aşağıdaki kod parçacığını Kod Önizleme kutusuna yapıştırın:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | // Function to get archives list with limited months function wpb_limit_archives() { $archive_title = '<h3>Archives</h3>' ; $my_archives = $archive_title . wp_get_archives( array ( 'type' => 'monthly' , 'limit' =>6, 'echo' =>0 )); return $my_archives ; } // Create a shortcode add_shortcode( 'wpb_custom_archives' , 'wpb_limit_archives' ); // Enable shortcode execution in text widget add_filter( 'widget_text' , 'do_shortcode' ); |
'Limit'=>6
yazan kısım görüntülenen ay sayısını kontrol eder. İsterseniz bunu herhangi bir sayı ile değiştirebilirsiniz.
Şimdi, Ekleme bölümüne gidin ve Ekleme yönteminin ‘Otomatik Ekleme’ olduğundan emin olun. Ayrıca, Konum için ‘Yalnızca Ön Uç’ seçeneğini seçin.
Bunu yaptıktan sonra, kodu ‘Etkin’ hale getirmek için üstteki geçişe tıklayın ve ‘Snippet’i Kaydet’ düğmesine basın.

İşiniz bittiğinde, blok tabanlı widget düzen leyicinize veya tam site düzenleyicinize gidin.
Ardından, ‘+’ düğmesine tıklayın ve ‘Kısa kod’ bloğunu seçin.

Bundan sonra, aşağıdaki kısa kodu bloğa yapıştırmalısınız:
[wpb_custom_archives]
‘Güncelle’ veya ‘Kaydet’ düğmesine tıkladığınızda, kenar çubuğunuzda sadece 6 aylık arşivler görüntülenecektir.

Daha fazla ayrıntı için WordPress’te görüntülenen arşiv aylarının sayısını sınırlama kılavuzumuzdaki Yöntem 3’e bakın.
İşte varsayılan Arşivler bloğunu kısa kodla değiştirdikten sonra arşivler bölümümüzün nasıl göründüğü:

Seçenek 5: Aylık ve Yıllık Arşiv Açılır Menülerini Görüntüleme
Bazen ziyaretçiler bir gönderinin tam olarak ne zaman güncellendiğini veya yayınlandığını bilemeyebilir. Onlara yardımcı olmak için arşivler bölümünüzde iki açılır menü oluşturabilirsiniz: biri yıllar, diğeri aylar için.
Bu WordPress tasarım öğesi, kullanıcıların uzun bir listede gezinmeden eski içerikleri bulmasını kolaylaştırabilir.
Bunun için özel bir kod parçacığı ve WPCode kullanacağız. Daha önce olduğu gibi, önce WordPress yöneticinize WPCode’u yüklediğinizden emin olun.
Ardından, Kod Parçacıkları ” + Parçacık Ekle’ye gidin. ‘Özel Kodunuzu Ekleyin (Yeni Snippet)’ seçeneğini seçin ve ‘+ Özel Kod Ekle’ düğmesine tıklayın.
Şimdi, yeni özel kod parçacığınıza bir ad verin. ‘Aylık ve Yıllık Arşiv Açılır Menüleri’ gibi basit bir şey olabilir.
Ayrıca, ‘Kod Türü’ için ‘PHP Snippet’i seçin.

Kod Önizleme kutusuna aşağıdaki kod parçacığını ekleyin:
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 32 33 34 35 36 37 38 39 40 41 42 43 44 | function custom_archive_dropdown_shortcode() { // Get months array global $wpdb , $wp_locale ; $months = $wpdb ->get_results( "SELECT DISTINCT YEAR(post_date) AS year, MONTH(post_date) AS month FROM $wpdb ->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" ); $output = '<h3>Archives</h3>' ; // Added 'Archives' title in H3 $month_dropdown = '<select id="archive-month" name="archive-month" onchange="document.location.href=this.options[this.selectedIndex].value;">' ; $month_dropdown .= '<option value="">Select Month</option>' ; foreach ( $months as $month ) { $month_name = $wp_locale ->get_month( $month ->month); $year_month = sprintf( '%d-%02d' , $month ->year, $month ->month); $month_dropdown .= sprintf( '<option value="%s">%s %d</option>' , esc_url(home_url( '/' . $month ->year . '/' . $month ->month . '/' )), $month_name , $month ->year ); } $month_dropdown .= '</select>' ; // Get years array $years = $wpdb ->get_results( "SELECT DISTINCT YEAR(post_date) AS year FROM $wpdb ->posts WHERE post_type = 'post' AND post_status = 'publish' ORDER BY post_date DESC" ); $year_dropdown = '<select id="archive-year" name="archive-year" onchange="document.location.href=this.options[this.selectedIndex].value;">' ; $year_dropdown .= '<option value="">Select Year</option>' ; foreach ( $years as $year ) { $year_dropdown .= sprintf( '<option value="%s">%d</option>' , esc_url(home_url( '/' . $year ->year . '/' )), $year ->year ); } $year_dropdown .= '</select>' ; $output .= $month_dropdown . $year_dropdown ; // Append dropdowns to output return $output ; // Return the complete output } add_shortcode( 'archive_dropdown' , 'custom_archive_dropdown_shortcode' ); |
Önceki kod parçacığında olduğu gibi, Ekleme bölümüne gidin ve Ekleme Yöntemi için ‘Otomatik Ekleme’yi seçin. Konum için ise ‘Yalnızca Ön Uç’u seçebilirsiniz.
Ardından, kod parçacığını etkin hale getirin ve ‘Parçacığı Kaydet’e tıklayın.

Şimdi, blok tabanlı widget düzenleyicisine veya tam site düzenleyicisine gidin.
Bundan sonra, kenar çubuğunuza bir ‘Kısa Kod’ bloğu ekleyin. Bu aşamada, devam edebilir ve aşağıdaki kısa kodu kısa kod bloğuna yapıştırabilirsiniz:
[archive_dropdown]
Bunu yaptıktan sonra, ‘Güncelle’ veya ‘Kaydet’e tıklayın.

Artık, kullanıcıların doğru içeriği bulmak için ay ve yılı seçmelerine olanak tanıyan 2 açılır menü olacak.
Bir ay veya yıl seçtiklerinde, kullanıcı seçtiği dönemin arşiv sayfasına yönlendirilecektir.

Seçenek 6: Yıla Göre Düzenlenmiş Aylık Arşivleri Göster
Bir keresinde, kenar çubuğunda yıllara göre düzenlenmiş aylık arşivlere ihtiyaç duyan bir site tasarımı üzerinde çalışmamız gerekti.
Bu özel kenar çubuğu arşivinin kodlanması zordu çünkü bu müşteri yılı yalnızca solda bir kez göstermek istiyordu.

Neyse ki, web’den ilham alabildik ve bunun için özel bir kod parçacığı oluşturduk. Bu makale için, bu kodun WPCode kullanarak da kullanabileceğiniz çok daha basit bir versiyonunu bulduk.
İlk olarak, WordPress yöneticinize WPCode’u yükleyin. Bundan sonra, Code Snippets ” + Snippet Ekle‘ye gidin. ‘Özel Kodunuzu Ekleyin (Yeni Snippet)’ seçeneğini seçin ve ‘+ Özel Kod Ekle’ düğmesine tıklayın.
Devam edin ve yeni özel kod parçacığınıza bir ad verin. ‘Özel Arşivler’ gibi basit bir şey olabilir.
Ayrıca, ‘Kod Türü’ için ‘PHP Snippet’i seçin.

Kod Önizleme kutusuna aşağıdaki kod parçacığını ekleyin:
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 32 33 34 35 36 | add_shortcode( 'custom_archives' , 'display_custom_archives' ); function display_custom_archives() { $archives = wp_get_archives( array ( 'type' => 'monthly' , 'format' => 'custom' , 'before' => '' , 'after' => '<hr>' , 'echo' => false, ) ); // Split the archives by year $archives_by_year = array (); foreach ( explode ( '<hr>' , $archives ) as $archive_item ) { if ( empty ( $archive_item ) ) { continue ; } // Extract year from the archive link preg_match( '/\/(\d{4})\//' , $archive_item , $matches ); $year = isset( $matches [1] ) ? $matches [1] : date ( 'Y' ); // Add to the year array $archives_by_year [ $year ][] = $archive_item ; } // Build the output $output = '<h2 class="archives-title">Archives</h2>' ; $output .= '<hr>' ; $output .= '<table>' ; foreach ( $archives_by_year as $year => $archives_for_year ) { $output .= '<tr>' ; $output .= '<td class="year">' . $year . '</td>' ; $output .= '<td class="months">' ; $output .= implode( '' , $archives_for_year ); $output .= '</td>' ; $output .= '</tr>' ; } $output .= '</table>' ; return $output ; } |
Yöntem 5’te gösterildiği gibi, şimdi Ekleme bölümüne gidebilir ve Ekleme Yöntemi için ‘Otomatik Ekleme’yi seçebilirsiniz. Konum için ‘Yalnızca Ön Uç’ seçeneğini belirleyebilirsiniz.
Şimdi kod parçacığını etkin hale getirin ve ‘Parçacığı Kaydet’e tıklayın.

Tekrar yeni bir özel kod parçacığı oluşturalım. Bu kez kod parçacığı, arşiv widget alanını CSS kullanarak şekillendirecek.
Bu kod parçacığını ‘Arşivler için Özel CSS’ olarak adlandırabilir ve Kod Türü için ‘CSS Parçacığı’nı seçebilirsiniz.

Şimdi, aşağıdaki kod parçacığını Kod Önizleme kutusuna yapıştırın:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | .archives-title { /* Style the title */ } table { width : 100% ; border-collapse : collapse ; } td { padding : 5px ; vertical-align : top ; } .year { font-weight : bold ; } .months hr { margin : 5px 0 ; border : none ; border-top : 1px solid #ccc ; } |
Tamamlandığında, Ekleme bölümüne gidin ve Ekleme Yöntemi için ‘Otomatik Ekle’yi seçin. Ardından, Konum için ‘Site Genelinde Üstbilgi’yi seçin.
Bundan sonra, kodu etkin hale getirin ve ‘Snippet’i Kaydet’e tıklayın.

Widget düzenleyicisine veya tam site düzenleyicisine gidelim.
Burada, ‘+’ düğmesine tıklayın ve ‘Kısa Kod’ bloğunu seçin. Şimdi, devam edin ve aşağıdaki kısa kodu kısa kod bloğuna yapıştırın:
[custom_archives]
Ardından, ‘Güncelle’ veya ‘Kaydet’e tıklayın.

Bu kadar!
Demo web sitemizdeki arşiv ekranımız bu şekilde görünüyor:

Daha Fazla WordPress Blog İpucu ve Püf Noktası Keşfedin
WordPress blog arşivlerinizi daha da geliştirmek ister misiniz? Ya da belki kenar çubuğunuzu yeniden tasarlamak? Aşağıdaki ilgili kılavuzlara göz atın:
- Her Kategori için Özel Kenar Çubuğu, Üstbilgi veya Altbilgi Ekleme
- WordPress’te Özel Yazı Türleri Arşiv Sayfası Nasıl Oluşturulur
- WordPress’te Özel Arşiv Sayfası Nasıl Oluşturulur?
- WordPress’te Kenar Çubuğu Tarafı Nasıl Değiştirilir
- Maksimum Sonuç Almak için WordPress Kenar Çubuğu Hileleri
- WordPress Kenar Çubuğu Widget’ına Nasıl Görsel Eklenir
Umarız bu eğitim, kenar çubuğunuzdaki WordPress arşivlerinin görünümünü nasıl özelleştireceğinizi öğrenmenize yardımcı olmuştur. Ayrıca bir WordPress web sitesinin nasıl düzenleneceğine ilişkin nihai kılavuzumuza ve en iyi WordPress sürükle ve bırak sayfa oluşturucuları uzman seçimlerimize 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.
AD
Is there a way, or a widget of some kind, under the Archives sidebar to have blog posts by title displayed under under the correlating month; versus just the month alone being present that clicks into a new page displaying all posts for that month in their entirety?
I’m sorry if this has already been answered in the comments. I haven’t had a chance to read them.
Thank you for any help or direction you can provide my question!
WPBeginner Support
Hello,
Please see our article on how to limit archives in WordPress.
Admin
Jaswinder
Thanks a lot for the code. Its a life saver.
Carla Izumi Bamford
Thanks for this post, very helpful.
Margaret
This was extremely helpful! Thank you so much. Did exactly what I needed it to.
Thomas
Hello WPBEGINNER,
I hope you still have a look at this older post. First many thanks for this great tutorial and code.
I’ve managed to get
Year
January (2)
February (5)
…
…
But didn’t manage to count the posts per year. How can I do this, so that the year entry shows a number for all post for a year
year (28) …
Many thanks for your help!
Best regards,
Thomas
Erik
Thanks so much for this code!
it is helping me a lot.
Any chance to extend this to a specific category? by category id?
Jason Wofford
The code is working perfectly but how can I add Days to each of the months?
Tony Lewis
did not work for me seems to be missing some css
Xavier
Is this code no longer working for anyone else out there??
James
It does work at all !!!
result has nothing to do with example.
Strange that some guys felt it useful and great.
What is the issue ?
Eldad
Just wanted to beem thanks
Xavier Bonet
Hi! First thing’s first! Great code! Works perfectly! Thanks!
I was asking myself if there would be a way to edit the code in order to allow for the, say, 18-month span to move up or down according to what one is viewing? As is, you can only access the last 18 months. But perhaps there would be a way to do this so that when one opens up, for example, month 18 of the list, and the new page is opened, the archive list output by the code above sets month 18 as the middle of a new array showing, say, 9 months before and 7 after (or vice-versa).
Perhaps my explanation is not too clear. I got the idea when viewing this website here: http://marthabeck.com/. If you scroll down to the menu at the very bottom you will see there are several years available but only those months for the present year are displayed. When one opens up a new year, the months for that year are then displayed. Of course, this is probably another code entirely, but at least it works as a visual example of sort of what I’m talking about.
WPBeginner Support
Try creating it with conditional tags on date based archives templates:
Look codex for is_archive single_month_title
Admin
tobias
Not the foreach() loop, the MySQL query should have a limit!
Jessica
Is there a way for the archive be be daily or even weekly rather than just by month?
Editorial Staff
You can use the calendar widget in WordPress.
Admin
JP Lew
I use a calendar, but in addition to that modified the code to output daily archives too, it worked great. Here’s the query:
$days = $wpdb->get_results(“SELECT DISTINCT DAY( post_date ) AS day , MONTH( post_date ) AS month , YEAR( post_date ) AS year, COUNT( id ) as post_count FROM $wpdb->posts WHERE post_status = ‘publish’ and post_date <= now( ) and post_type = 'lecture' GROUP BY day , month , year ORDER BY post_date ASC");
<a href="/year; ?>/month, 1, $day->year)) ?>/month, $day->day, $day->year)) ?>”>month, $day->day, $day->year)) . “, ” . date_i18n(“F”, mktime(0, 0, 0, $day->month, 1, $day->year)) . ” ” . date(“j”, mktime(0, 0, 0, $day->month, $day->day, $day->year)) . “, ” . $queried_year ?>post_count . “)”; ?>
//outputs: Thursday, August 22, 2013 (12)
Thanks for the post by the way, it was exactly what I was looking for. The performance is surprisingly good too.
JP Lew
ok, your comment system stripped out all my `php` tags essentially rendering that code useless. Anyways, it’s possible and easy, you’ll figure it out.
Roelof
Hello,
I like this idea. Can it also be adapted so only articles in a specific category will be in the archives and all the other categories not.
Roelof Wobben
Asher Charles
Great little pice of code, been looking for a way to better display archives. Cheers
Carla
I’ve looked everywhere for a tutorial on how to customize my archives page. I was able to get my page to produce a list of post titles and post dates, which is a great start. And now I need to figure out how to group them by month, so the page looks like this:
2013
May
This is a post title
May 28, 2013
And another post
May 20, 2013
I’m not really sure how to do this. Would you have any suggestions? I’ve noticed in the WordPress forum and elsewhere that lots of people want their archives to look like this, but they (like me) haven’t received any help.
Thank you!
Núria
Thanks for this code snipped, it has been very usefull. I only want to add a little bit change that will make the output of the month’ string in the locale language.
On line 16 you can replace the date() function to date_i18n() function
– echo date(“F”, mktime(0, 0, 0, $month->month, 1, $month->year))
– echo date_i18n(“F”, mktime(0, 0, 0, $month->month, 1, $month->year))
Thus, the function will return for the march month the string “March” in English, “Marzo” in spanish or “Març” in catalan, only to put some examples, based on the language of the site.
Editorial Staff
Thank you for this suggestion. Updated the code.
Admin
Matt
The theme I’m using has a widget for the sidbars. The php file is written in shortcode. How would I convert this to a shortcode to put into the file? Thanks.
Editorial Staff
Take the first snippet and convert it into a function. Then use this article to create a shortcode:
https://www.wpbeginner.com/wp-tutorials/how-to-add-a-shortcode-in-wordpress/
Admin
Ryan
Hey,
I came across this, just what i was after. But it has a small problem, i have the last two months of posts october and november show in sidebar, i just added a new one in december and its not showing december in the archive list.
Weird why its not showing the current month
Editorial Staff
That is indeed weird. We have this running fine on a client’s website.
Admin
thao_
Is it possible to show the total years’ post_count, as well as the post_count for each month? So you’d still have each months’ post count next to each month, but also the total for the year next to the year. Using your archive image as the example, you’d have 2010 (20) and then the months as the currently display.
Editorial Staff
Yes, you can add the counts of all the months in a year and display it if you want.
Admin
craig coffman
I think I got it sorted. I moved the “break;” up into the code before it spits out the monthly … . I figured it out after looking at Appleton’s site. His code is slightly different, as you noted. I find it interesting how people can change a single bit of code and the effect is wildly different from such a small edit. To borrow from WP, “Code is Poetry”
I did make one alteration which I wanted to bring to your attention. The above code did not seem to spit out the most current month. That is, my August month of this year would not appear (since we are now in August) but July showed just fine. I altered the SQL statement and now it does appear. I am not sure you want the current month, but if this is an archive perhaps even the current month is archived.
Here is my change:
post_date YEAR(CURDATE())
That seems to pull the month we are currently in. I am no SQL master, so perhaps there is a reason not to do this or even a better way. However it is working for me.
Thanks for your time on this tutorial. It definitely saved me from further bashing my head against a wall attempting to manipulate wp_get_archives().
craig coffman
hmm… seems like some code was stripped out. There should be the Greater Than symbol in there, between “post_date” and “YEAR(CURDATE())”. Let me try again and I hope it takes.
post_date > YEAR(CURDATE())
Sorry for the additional post, but a ‘tweak’ doesn’t change anything if the proper code does not display
Ryan
Hey Craig,
I am not sure where to put
post_date > YEAR(CURDATE())
Thanks
craig coffman
Ryan –
Weird. I posted a response on the Float Left site but it does not seem to be there. Here is the file for you to download, showing where the code is located:
http://www.octoberland.com/fileChute/displayCurrentMonth.zip
I put the code in the index.php file from my template. It is there because the client wanted it to be on every page. It only grabs the current year’s months. That is, if you went back to 2011 the months displayed would still be 2012.
I added my code into the ‘WHERE’ line of the MySQL, replacing the code Andy had there.
Also, I have the standard WP archive function in there as well because my client wanted to display a yearly archive as well. This is not necessary for displaying the current month.
I hope this helps.
– Craig
Ryan
Thank you craig, that seems to have fixed the issue.
craig coffman
Ryan –
Happy it worked for you. It took me several hours (I am not a MySQL developer) to figure that out. Now that it is helped someone else, it was worth the effort
– Craig
mary
how to display the days?
Editorial Staff
You want to display all 30 days for all the months? Or do you just want to display the days? You might be better of using the built-in calendar widget.
Admin
Akshat Goel
Great post!! Saved my day!
zuzanka
Hi, I’m using only widget, not extra plugin for archive. I limited number of months, e.g. 2 but I’m expecting to have 2 months and than the rest under “…” or “archive”. I can not find the way how to show the rest. Is here someone who knows this problem? Thanks a lot.
wpbeginner
@sgclark That sounds good. Will have to test out his plugin and then add it in this article
sgclark
@wpbeginner The unused months are wrapped in their own unique CSS class, so you can just do a CSS “display:none” for unused months. Then when a post appears in the month, it switches to a different class (via PHP)
wpbeginner
@sgclark That plugin sounds good… Wonder how that would work if we don’t want to show the unused months at all. But nonetheless haven’t tried it yet because it is not hosted in the repository…
sgclark
Justin Blanton created a neat WordPress plug in called SmartArchives. I am sure you could dig into his CSS file as well to play with the display and you don’t have to worry about all the extra code on the Sidebar PHP page. – http://hypertext.net/projects/smartarchives