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

WordPress’te Son Gönderileri Açılır Menü Olarak Gösterme

WordPress’teki Kategori widget’ına muhtemelen aşinasınızdır. Son zamanlarda, okuyucularımızdan biri bize son gönderileri de bir açılır menüde göstermenin mümkün olup olmadığını sordu. Bu makalede, WordPress’te son gönderileri bir açılır pencere olarak nasıl göstereceğinizi göstereceğiz.

Add recent posts as drop down menu

Açılır Menüde Son Gönderilere Neden ve Kim İhtiyaç Duyar?

WordPress, herhangi bir kenar çubuğuna veya widget hazır alana ekleyebileceğiniz yerleşik bir son gönderiler widget’ı ile birlikte gelir.

Bu widget basitçe son gönderilerin bir listesini görüntüler ve göstermek istediğiniz gönderi sayısını seçebilirsiniz. Ancak 5-10’dan fazla gönderi göstermek istiyorsanız, liste kenar çubuğunuzda çok fazla yer kaplayacaktır.

Bazı WordPress kullanıcıları son gönderileri görüntülemek için kompakt bir yola ihtiyaç duyabilir. Bu durumda, açılır pencereler veya daraltılabilir listeler kullanmak yerden tasarruf etmenize yardımcı olabilir.

WordPress’te son gönderileri açılır menü olarak göstermenin birkaç farklı yoluna göz atalım.

WordPress Son Yazıları Düz Açılır Menüde Gösterme (Manuel Kod)

Bu yöntem, yerleşik wp_get_recent_posts işlevini kullanır. Tek yapmanız gereken aşağıdaki kodu kopyalayıp temanızın functions.php dosyasına veya siteye özel bir eklentiye yapıştırmaktır.

function wpb_recentposts_dropdown() { 
$string .= '<select id="rpdropdown">
			<option  value="" selected>Select a Post</option>';

$args = array( 'numberposts' => '5', 'post_status' => 'publish' );

$recent_posts = wp_get_recent_posts($args);
	foreach( $recent_posts as $recent ){
		$string .= '<option value="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</option> ';
	}

$string .= '</select>
			<script type="text/javascript"> var urlmenu = document.getElementById( "rpdropdown" ); urlmenu.onchange = function() {
      		window.open( this.options[ this.selectedIndex ].value, "_self" );
 			};
			</script>';

return $string;
} 
add_shortcode('rp_dropdown', 'wpb_recentposts_dropdown');
add_filter('widget_text','do_shortcode');

Artık [rp_dropdown] kısa kodunu WordPress yazılarınızda, sayfalarınızda ve metin widget’larınızda kullanabilirsiniz. Bu şekilde görünecektir:

Recent posts in a drop down menu on a WordPress site

Eklenti Kullanarak Katlanabilir Son Gönderiler Ekleme

Yukarıdaki yöntem basitçe son gönderilerinizi bir açılır formda listeler. Yerden tasarruf etmenin bir başka yolu da, kullanıcılar üzerine tıkladığında genişleyen daraltılabilir bir son gönderiler listesi eklemektir.

Yapmanız gereken ilk şey Collapse-O-Matic eklentisini kurmak ve etkinleştirmek. Kutudan çıktığı gibi çalışır ve yapılandırmanız gereken herhangi bir ayar yoktur.

Eklenti, bir kısa kod kullanarak herhangi bir şeyi daraltılabilir bir menüde göstermenize olanak tanır.

Bu eklentiyi kullanmadan önce, son gönderileri istediğimiz yerde kolayca göstermenin bir yoluna ihtiyacımız var. Bu kodu temanızın functions.php dosyasına veya siteye özel bir eklentiye eklemeniz yeterlidir.

function wpb_recentposts() { 

$string .= '<ul>';
$args = array( 'numberposts' => '5', 'post_status' => 'publish' );
$recent_posts = wp_get_recent_posts($args);
	foreach( $recent_posts as $recent ){
		$string .= '<li><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a></li> ';
	}
$string .= '</ul>';
return $string;
} 
add_shortcode('recentposts', 'wpb_recentposts');
add_filter('widget_text','do_shortcode');

Bu kod, [recentposts] kısa kodunu kullanarak son gönderilerin bir listesini görüntülemenizi sağlar.

Şimdi son gönderilerin daraltılabilir bir listesini oluşturmak için kısa kodumuzu Collapse-O-Matic kısa koduna ekleyeceğiz.

Kısa kodu aşağıdaki gibi eklemeniz yeterlidir:

[expand title="Recent Posts"][recentposts][/expand]

Bu kısa kodu WordPress sitenizdeki bir metin widget’ına, yazılara veya sayfalara ekleyebilirsiniz. Test sitemizde bu şekilde görünüyordu.

Collapsable list of recent posts

Hepsi bu kadar, umarız bu makale WordPress’te son gönderileri açılır menü olarak göstermenize yardımcı olmuştur. WordPress’te harika bir editoryal takvim oluşturmak için bu 6 ipucunu da görmek isteyebilirsiniz.

Bu makaleyi beğendiyseniz, WordPress video eğitimleri için lütfen YouTube Kanalımıza abone olun. Bizi Twitter ve Facebook‘ta da bulabilirsiniz.

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

17 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. Yvonne Manders says

    Hi,

    I installed the collapse-o-mattic and pasted the code in the functions.php file.
    After that I pasted the shortcode [expand title=”Recent Posts”][recentposts][/expand] in a textwidget, but nothing happened.
    Am I missing something?

    Best regards, Yvonne

    • WPBeginner Support says

      You would want to place the shortcode in the text editor rather than the visual editor to ensure you don’t have styling blocking the shortcode from working.

      Yönetici

  3. Erika says

    Line 3 has an error. The closing option tag is missing its closing “/”. This is generating a blank option in the menu.

  4. Amjad says

    Hi there. I have used above code to show all my posts in a drop down but its not sorted. I have two questions here:
    1. How can i sort posts by title?
    2. How can i show posts of a specific category in dropdown instead of showing all posts?

  5. Rolando says

    Nice article! How can you make it by a specific category and not just all your categories? Also, can it be done alphabetical?

  6. Farai Mugaviri says

    Thank you so much for the great help there. I wouldalso want to display categories in a dop-down list, if you can help with that…. But now what if I update my WordPress, is it even possible? I saw somewhere they talked about challengess when updating the wordpress and risking losing data because of hardcoding the PHP functions

  7. Robert says

    Great tool, thanks for that!
    Is it possible to sort the post output in the list in alphabetical order?
    Thanks in advance for your reply!

    Regards,
    Robert

  8. Andre says

    Its possible to show the posts dropdown with a button to submit?

    ‘function wpb_recentposts_dropdown() {
    $string .= ‘
    Select your School’;

    $args = array( ‘numberposts’ => ‘5’, ‘post_status’ => ‘publish’ );

    $recent_posts = wp_get_recent_posts($args);
    foreach( $recent_posts as $recent ){
    $string .= ” . $recent[“post_title”].’ ‘;
    }

    $string .= ‘
    FIND SCHOOL NOW
    var urlmenu = document.getElementById( “submitschool” ); urlmenu.onclick = function() {
    window.open( this.options[ this.selectedIndex ].value, “_self” );
    };
    ‘;

    return $string;
    }
    add_shortcode(‘rp_dropdown’, ‘wpb_recentposts_dropdown’);
    add_filter(‘widget_text’,’do_shortcode’);’

  9. NG SHAIKH says

    It is an excellent article. Beginners like me can understand power of WordPress and its plug-ins by such articles.

    I would be enlightened if some articles are written to display a message on specific page and not on all posts and pages.

    It will also help beginners if a few articles are written to display a form for user entry which can be saved in the database

  10. Julie S says

    I really like the drop-down menu of recent posts. How can I control the width of this drop down menu? It defaults too long for my sidebar.

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.