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 jQuery SSS Akordeonu Nasıl Eklenir

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.

Geçenlerde kullanıcılarımızdan biri bize WordPress sitelerine SSS akordeonu eklemenin bir yolu olup olmadığını sordu. WordPress’te sıkça sorulan sorular veya SSS bölümü eklemenize olanak tanıyan birçok eklenti mevcuttur. Bu makalede, WordPress sitenize nasıl bir jQuery SSS akordeonu ekleyeceğinizi göstereceğiz.

Akordeon nedir?

Web tasarımında akordeon, kullanıcı etkileşimi üzerine daralan veya genişleyen sekmelere veya içerik bloklarına sahip bir kullanıcı arayüzü tasarım modeli için kullanılan bir terimdir. Her sekmenin altında, kullanıcı menü öğesine tıkladığında genişleyen içerik bulunur. Basit bir ifadeyle, üzerine tıkladığınızda genişleyen bir menü gibidir. Ücretsiz WordPress blog kurulum sayfamızda da benzer bir efekt kullandık. Aşağıda örnek bir akordiyonun ekran görüntüsü yer almaktadır.

An accordion menu for FAQs

Video Eğitimi

Subscribe to WPBeginner

Videoyu beğenmediyseniz veya daha fazla talimata ihtiyacınız varsa, okumaya devam edin.

Bir jQuery SSS Akordeonu Ekleme

Bir jQuery SSS akordeonu eklemeden önce, bir SSS bölümünüz olduğundan emin olmanız gerekir. WordPress’te SSS bölümünün nasıl ekleneceğine ilişkin eğitimimizi takip ederek SSS bölümü eklemeye başlayın.

Şimdi jQuery SSS akordeonunu eklemeye devam edelim. WordPress jQuery kütüphanesi ile birlikte gelir ancak jquery temaları yoktur. Bunu Google CDN’den yükleyeceğiz ve bu komut dosyalarını WordPress’te sıraya koyacağız. Ayrıca sıkça sorulan sorularımızı görüntüleyen bir kısa kod oluşturacağız. En önemlisi, tüm bunları bir WordPress eklentisi oluşturarak yapacağız.

Masaüstünüzde bir klasör oluşturun ve adını my-accordion koyun. Not Defteri’ni veya seçtiğiniz başka bir metin düzenleyiciyi açın. my-accordion.php adında bir dosya oluşturun ve bu kodu içine yapıştırın:

<?php
/** 
Plugin Name: WPBeginner's FAQ Accordion
Description: A jQuery powered Accordion for FAQs based on a tutorial by WPBeginner
Version: 1.0
Author: WPBeginner
Author URI: https://www.wpbeginner.com
License: GPL2
*/
function accordion_shortcode() { 

// Registering the scripts and style
wp_register_style('wpb-jquery-ui-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/humanity/jquery-ui.css', false, null);
wp_enqueue_style('wpb-jquery-ui-style');
wp_register_script('wpb-custom-js', plugins_url('/accordion.js', __FILE__ ), array('jquery-ui-accordion'), '', true);
wp_enqueue_script('wpb-custom-js');

// Getting FAQs from WordPress FAQ Manager plugin's custom post type questions
$posts = get_posts(array(  
'posts_per_page' => 10,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'question',
));
	
// Generating Output 
$faq  .= '<div id="accordion">'; //Open the container
foreach ( $posts as $post ) { // Generate the markup for each Question
$faq .= sprintf(('<h3><a href="">%1$s</a></h3><div>%2$s</div>'),
$post->post_title,
wpautop($post->post_content)
);
}
$faq .= '</div>'; //Close the container
return $faq; //Return the HTML.
}
add_shortcode('faq_accordion', 'accordion_shortcode');

Değişikliklerinizi bu dosyaya kaydettikten sonra yeni bir boş dosya açın. Bunu accordion.js olarak kaydedin. Daha sonra bu kodu içine yapıştırın ve dosyayı kaydedin:

jQuery(document).ready(function() {
jQuery("#accordion").accordion();
})();

Şimdi eklentimiz yüklemeye hazır. FTP İstemcinizi açın ve my-accordion klasörünü WordPress web sitenizdeki /wp-contnt/plugins/ dizinine yükleyin. Daha sonra, WordPress yönetici alanında eklentinizin ekranına giderek eklentiyi etkinleştirmeniz gerekir.

Accordion ile SSS sayfası ekleme

Bu SSS’leri akordeon biçiminde görüntülemek için yeni bir sayfa oluşturmanız gerekir. Sayfalar ” Yeni Ekle‘ye gidin. Sayfanıza SSS gibi bir başlık verin ve sayfa düzenleme alanına bu kısa kodu girin:

[faq_accordion]

Sayfanızı kaydedip yayınlayın ve önizlemesini yapın. SSS’lerinizin güzel bir akordeon menüde görüntülendiğini göreceksiniz.

Akordeonunuzun Stilini ve Renklerini Değiştirme

Renkler ve stil için bu SSS Akordeonu Google’da barındırılan jQuery UI Temalarını kullanır. Temelde bir stil sayfasıdır ve isterseniz indirip kendi web sitenize koyabilirsiniz. jQuery web sitesinde birkaç kullanıma hazır tema içeren bir jQuery UI temaları bölümü vardır. Gördüğünüz gibi biz eklentimizde humanity temasını kullandık. Bunu smoothness, cupertino vb. gibi mevcut temalardan herhangi biriyle değiştirebilirsiniz. Bu temaları Themeroller üzerinde de oluşturabilir veya değiştirebilirsiniz.

jQuery UI Themes

Umarız bu makale WordPress web sitenize bir jQuery SSS Akordeonu eklemenize yardımcı olmuştur. Geri bildirim ve sorularınız için lütfen aşağıya bir yorum bırakın.

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

46 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. Zac Smith says

    Hello, I installed the Quick and Easy FAQ plugin, and then followed this video. I do not get an accordion FAQ, rather the only thing that shows up is the first FAQ question and answer … and the question is hyperlinked.

  3. Daniel says

    Great tutorial!

    My debugger complained about undefined variable $faq.
    Defined variable at begin of function accordion_shortcode() with $faq = ”;

    As well my version of FAQ plugin enters the value ‘faq’ instead of ‘query’ into the field post_type of the table postes.

    Adjusted line 23:
    ‘post_type’ => ‘faq’,

  4. Johan Johnsson says

    It’s silly that you’ll have us install a plugin for a FAQ page and follow your previous tutorial on how to make that FAQ page, and then copy (essentially download) the plugin you made for this tutorial. So we’re essentially downloading 2 already finished plugins.

    I don’t think people come here to download 2 plugins, but rather to LEARN how to make a custom accordion menu of their own. I don’t see why I should follow this “how to guide” when I can just download some other WP plugin that does the same job, if not better.

    And the fact that this plugin relies on the FAQ plugin seems quite unnecessary. Why didn’t you make a stand-alone plugin and make it dynamic? So you can use it for any content on any page.

    • WPBeginner Support says

      Hi Johan,

      Most our users are beginners who would find it difficult to copy paste code. This is why we made it into a plugin so that users can download and install it. If you would like to use the code method, then the code is here for you to study and use it in your theme or a site-specific plugin. Let’s us know if you need any help with that.

      Yönetici

  5. Kim says

    How do I make it so that when I click the title it collapses – I see that it collapses when you click another part of the accordian but I am looking for the function to collapse when each title is clicked.

  6. christina says

    thanks for the tutorial. I am very much new to coding and webpage design. I have followed instructions to pasting the codes to my notepad on my mac. Is there a different way to save the file other than in notepad as a php or js file into the folder? Also, could you please let me know step by step how to open FTP client (what is it btw?) and how to upload my-accordian folder to /wp-contnt/plugins/directory to WP website. Thanks so much.

  7. WPBeginner Staff says

    The code screenshot you shared, does not look like the code we have shared above. However, the code in screenshot has HTML tags that shouldn’t be there. It should be like this:

    ‘posts_per_page’ => ’10’,

    • Stefan 13 says

      This is pretty weird. Your comments had me baffled, as I was clearly seeing the code right there on my screen. I then realised that all those currency converter tags came from another one of my Firefox plugins, which dynamically adds a context menu to numbers in web pages – hence the source looked different.
      Thanks for your help!

  8. Stefan 13 says

    When I try to activate the plugin in WP 4.1, I get this error message:

    Plugin could not be activated because it triggered a fatal error.

    Parse error: syntax error, unexpected ‘<' in /home2/laurepc3/public_html/shala/wp-content/plugins/my-accordion/my-accordion.php on line 20

    Any ideas that may help with this?

    • WPBeginner Staff says

      The code you pasted has an unexpected character 10,

      Make sure posts_per_page is enclosed in single quotes. Make sure there is an equals sign before greater than sign and make sure there is a comma at the end of the line.

      • Guest says

        I don’t have that on line 20. What I can see on line 20 in the post above and in my file is this:

        ‘posts_per_page’ => 10,
        Screen shot attached as well.
        So does the post above display incorrect file content?

      • Stefan 13 says

        The code in my file does not look like what you posted for line 20, but it’s the same code as is above:

        ‘posts_per_page’ => 10,
        ‘orderby’ => ‘menu_order’,

        Does that mean that the code in the article is out-of-date?
        Thanks for clarifying!

        Screen shot attached:

  9. Caroline says

    Thank you for this tutorial! It’s really help with my problem!

    I want to put topics like this: Topic “Events”: a accordion box and “Past Events”: another accordion box with topic Past Events. I tried the shortcode [faq_accordion + topic=”events”] but nothing happened. What can I do? Thank you very much!!!

  10. raouf says

    hello .. thank you for this tutorial, it’s helpful . but i just make a simple modification to make a accordion for a specific category . it worke’s but it show me the classic editor of my post not the visual editor. can you help me

  11. Rana says

    Hi
    Is there a way I can just dispay the “category title i.e FAQ Topic ” and the topic listed under each.
    I dont want the whole content,just the category title and clicking on it would show the topic title )

    Raba

  12. Chris says

    What’s the best way of getting the CSS to work? I have a child theme with my custom css code. Do I need to do anything in that file since I don’t see any of the Google css.

    • WPBeginner Support says

      Chris the Google CSS is queued and only fetched when your FAQ accordion is displayed. Open the page containing your FAQ Accordion and right click then select View Source. On the view source page look for http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/themes/humanity/jquery-ui.css if it is there then this means you have successfully loaded CSS theme.

      Yönetici

  13. Chris S. says

    I am able to get your plugin to work properly with the FAQ Manager but had some questions. It will only display 10 of the FAQs (which I presume is a default #). If I use the built-in shortcode that comes with the FAQ Manager plugin I am able to get the full list to display

    To display ALL: place [faq limit=”-1″] on a post / page

    Do you have any suggestions on how to handle this?

    Also, the FAQ manager allows for creating different lists by topic. Would there be a simple way to modify your plugin to make use of this?

    List all from a single FAQ topic category: place [faq faq_topic=”topic-slug”] on a post / page

    Great work otherwise!

    • WPBeginner Support says

      To display FAQs with topics FAQ Manager uses these parameters in the shortcode:

      [faq faq_topic="topic-slug"]

      [faq limit=”-1″] is quite self explanatory. It will display all FAQ.

      However, if you want to display more FAQ’s in the accordion you need to modify the query parameter in WPBeginner’s FAQ Accordion plugin, like this:

      // Getting FAQs from WordPress FAQ Manager plugin's custom post type questions
      $posts = get_posts(array( 
      
      // Increase posts per page
      'posts_per_page' => 50, 
      
      // Get only FAQs under a specific topic
      // faq-topic is a taxonomy 
      //topic-name is the name of topic you want to display
      
      'faq-topic' => 'topic-name',
      'orderby' => 'menu_order',
      'order' => 'ASC',
      'post_type' => 'question',
      )); 
      

      Yönetici

  14. Garrett says

    This isn’t working for me quite as intended. Plugin activates successfully and the shortcode is being processed, but here’s what the output looks like…

    I opted to use the FAQ manager plugin with your code in order to fix the hideous styling the plugin spits out.

    But when it’s all said and done, here’s what it looks like. Any tips?
    http://screencast.com/t/K2VfuBOptcn

    Many thanks in advance!!
    ~Garrett
    Atlanta, GA

    • Garrett says

      It seems the list is not inheriting any styling info from jquery-ui.css, though I did verify that a link file to jquery-ui.css IS present on the page.

      Line where jquery-ui.css is included:
      Exploring CSS rules:

      How can this be?

      Thank you!
      ~Garrett

  15. Richard Morrison says

    This has broken following the latest WordPress Update. I can no longer get the accordion to display. Shortcode now only displays the text from FAQ manager.

  16. Piet says

    line 20 of your my-accordion.php file reads: ‘numberposts’

    that function has been deprecated since…. a very long time.

    as you guys are in the business of giving tutorials to beginners, can you at least get the functions right?

    obviously this should be ‘posts_per_page’

  17. Mary-Anne says

    I would appreciate some help with this. I am attempting to install on a 3.5.2 on a network site. Network Admin has the Plugin listed and Network Activated.

    However it is not listed in the sub-sites.

    Has this been tested with Network sites yet? It looks like just what is needed. Thanks for all your efforts with WPBEGINNER.

    Thanks.

  18. birge says

    Hi,
    I made my-accordion.php and accordion.js, uploaded them and everything, but still I can’t see the plugin in the list of plugins. What went wrong?
    Thanks,
    birge

  19. Drake says

    Thank you for the article. It would be nice have a similar one that explain how to introduce jQuery tabs to pages/posts.

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.