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

WordPress’te Dinamik Widget Hazır Kenar Çubukları Nasıl Eklenir

Widget’lar WordPress temalarının o kadar ayrılmaz bir parçasıdır ki, widget’sız bir WordPress teması hayal etmek zordur. Widget’lar, kenar çubuklarınıza veya temanızdaki diğer widget hazır alanlara sürükleyip bırakabileceğiniz çalıştırılabilir komut dosyalarıdır. Okurlarımızın çoğu kenar çubuğuna özel öğeler eklemek için widget’lardan yararlanıyor. Ancak bu makale, WordPress temalarında dinamik widget hazır kenar çubukları veya widget hazır alanların nasıl ekleneceğini öğrenmek isteyen meraklı kullanıcılar içindir.

WordPress’te Kenar Çubuklarını veya Widget Hazır Alanları Kaydetme

Yapmanız gereken ilk şey, temanız için kenar çubuğunuzu veya widget hazır alanınızı kaydetmektir. Birden fazla kenar çubuğu ve widget hazır alanı kaydedebilirsiniz. Bu kodu kopyalayıp temanızın functions.php dosyasına yapıştırın

function wpb_widgets_init() {

	register_sidebar( array(
		'name' => __( 'Main Sidebar', 'wpb' ),
		'id' => 'sidebar-1',
		'description' => __( 'The main sidebar appears on the right on each page except the front page template', 'wpb' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );

	register_sidebar( array(
		'name' =>__( 'Front page sidebar', 'wpb'),
		'id' => 'sidebar-2',
		'description' => __( 'Appears on the static front page template', 'wpb' ),
		'before_widget' => '<aside id="%1$s" class="widget %2$s">',
		'after_widget' => '</aside>',
		'before_title' => '<h3 class="widget-title">',
		'after_title' => '</h3>',
	) );
	}

add_action( 'widgets_init', 'wpb_widgets_init' );

Bu kodda, iki kenar çubuğu kaydettik. Widget’lar ekranında tanımlamak için onlara isim ve açıklama verdik. Açıklama parametresi, kullanıcılara bu kenar çubuğunun temada nerede göründüğünü söylemek için kullanılabilir. wpb üzerinde çalıştığımız temanın adıdır, burada bu dizeleri çevrilebilir hale getirmek için kullanılır. Bunu kendi tema adınızla değiştirmelisiniz.

Newly created sidebars appearing on Widgets screen

WordPress Tema Dosyalarına Dinamik Widget Hazır Kenar Çubukları Ekleme

Şimdiye kadar sadece Dinamik Kenar Çubuklarını kaydettik. Kullanıcılar Görünüm ” Widget ‘lar ekranından widget’ları bu kenar çubuklarına sürükleyip bırakabilirler. Ancak, bu kenar çubukları sidebar.php gibi bir şablonda veya görüntülemek istediğiniz başka bir yerde çağrılana kadar sitenizde görünmeyecektir. Bu widget alanlarını eklemek için, bunları görüntülemek istediğiniz şablon dosyasını düzenleyin ve bu kodu yapıştırın:

<?php if ( is_active_sidebar( 'sidebar-1' ) ) : ?>
	<div id="secondary" class="widget-area" role="complementary">
	<?php dynamic_sidebar( 'sidebar-1' ); ?>
	</div>
<?php endif; ?>

Bu örnek kodda, burada görüntülemek istediğimiz kenar çubuğunu çağırmak için sidebar id’sini kullandık. Başka bir kenar çubuğu görüntülemek için kenar çubuğu kimliğini değiştirin. Örneğin, footer alanı için üç sidebar kaydedebilir ve ardından temanızın footer .php şablonunda bunları tek tek çağırabilirsiniz.

Widget’lar çok güçlü olabilir. Yazılarınıza ve sayfa içeriğinize widget ekleyebilir, metin widget’larınızı renkli hale getirebilir veya varsayılan WordPress widget’larının gücünü artırabilirsiniz. Doğru yerleştirilmiş widget hazır kenar çubukları, kullanıcıların basit sürükle ve bırak arayüzünü kullanarak web sitelerine özel öğeler eklemelerine olanak tanır.

Bu makalenin WordPress’te dinamik widget hazır kenar çubuklarının nasıl ekleneceğini öğrenmenize yardımcı olduğunu umuyoruz. Profesyonellerin ürünlerinde bunları nasıl kullandıklarını öğrenmek için Genesis gibi tema çerçevelerindeki kodları incelemenizi tavsiye ederiz. Sorularınız ve geri bildirimleriniz için lütfen aşağıya yorum bırakın.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

27 yorumLeave a Reply

  1. Hallo team again,

    sorry to trouble you, but I would like to specify, that I would need one widget above the themes current Primary Sidebar widget on the right and the other widget on the left side from the article in the middle.
    How should I proceed?
    Thank you,

    Milada

  2. Hallo team again,

    how do I add a field in the widget and which and where do I paste a field code to have there affiliate links?
    Thank you,

    Milada

  3. This tutorial was a great help.
    Been trying to accomplish this for about a week now.
    Nice and to-the-point.

    Thank you!

  4. I just wondered, before I actually paste the code, does this work on a theme that originally doesn’t come with a sidebar? I’m using Book Lite which only has footers.

  5. I am having trouble getting the widget to display o.O

    The widget is registering and displaying in the back-end properly with no issues, however, it will only show my widget content if I include content in the previous widget.

    I’m using a 2011 child theme and registering an additional footer area.
    functions.php snippet:
    https://gist.github.com/gWorldz/76273b5901e1b5c4759b#file-functions-php
    sidebar-footer.php
    https://gist.github.com/gWorldz/b6177ccc9734718dd636#file-sidebar-footer-php
    style.css
    https://gist.github.com/gWorldz/0f24a9350da164ee2f29#file-style-css

    Do you have any idea what I’m doing wrong or what is causing this issue?

  6. Just wanted to say thanks for this. I Googled to find out how to register a sidebar in WordPress, and hit a few other sites before this one, and yours had the best, clearest, most understandable directions. Well done.

  7. Finally i got my dynamic widget ready sidebar after 23 days… I was googled all the sites.. and finally i redirected @ your site.

    Thanks

  8. In the second snippet, where you are inserting the widget code into the template, where you have

    div id=”secondary”

    Should that id change with each widget area.

    Ex:

    First, Secondary, Third, fourth, etc

  9. Works for registering the sidebars but when I go to the Appearance » Widgets screen I see all my widgets but nothing to drag them into.

  10. Hi –

    This is a very helpful post. Thankyou!

    I’ve been successful using one dynamic widget area, now I’m trying to implement more than one. Everything seems to work as expected, except an odd problem in the dashboard. If I drag a text widget to my second dynamic widget area I can add content as you would expect, and save it, and it produces output on my pages as expected, however if I now revisit the dashboard widgets page, the second widget area does not appear to contain any widgets.

    I am using a twentytwelve-child theme, and WordPress 3.7.1.

    Any thoughts?

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.