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

Jak dodać widżet jQuery Tabber w WordPress?

Uwaga redakcyjna: Otrzymujemy prowizję z linków partnerskich na WPBeginner. Prowizje nie mają wpływu na opinie i oceny naszych redaktorów. Dowiedz się więcej o Proces redakcyjny.

Czy widziałeś obszar tabber na popularnych witrynach, który pozwala zobaczyć popularne, ostatnie i wyróżnione wpisy za pomocą jednego kliknięcia? Nazywa się to widżetem jQuery Tabber i pozwala zaoszczędzić miejsce na ekranie użytkownika, łącząc różne widżety w jeden. W tym artykule pokażemy, jak dodać widżet jQuery Tabber Widget w WordPress.

A jQuery powered tabber widget in WordPress

Dlaczego warto dodać widżet jQuery Tabber?

Prowadząc witrynę internetową WordPress, możesz łatwo dodawać elementy do paneli bocznych za pomocą widżetów typu „przeciągnij i upuść”. Gdy twoja witryna się rozrasta, możesz poczuć, że nie masz wystarczająco dużo miejsca na panelu bocznym, aby pokazać wszystkie przydatne treści. Dokładnie wtedy przydaje się tabulator. Umożliwia on wyświetlanie różnych elementów w tym samym obszarze. Użytkownicy mogą kliknąć na każdą kartę i zobaczyć treści, które ich najbardziej interesują. Wiele znanych witryn używa go do wyświetlania popularnych artykułów dzisiaj, w tym tygodniu i w tym miesiącu. W tym poradniku pokażemy jak stworzyć widżet tabber. Nie pokażemy jednak, co dodać w twojej karcie. Możesz dodać w zasadzie wszystko, co chcesz.

Uwaga: ten poradnik jest przeznaczony dla średnio zaawansowanych użytkowników i wymaga znajomości HTML i CSS. Początkujący użytkownicy powinni zapoznać się z tym artykułem.

Tworzenie widżetu jQuery Tabber w WordPress

Zaczynajmy. Pierwszą rzeczą, którą musisz zrobić, to utworzyć katalog na twoim pulpicie i nazwać go wpbeginner-tabber-widget. Następnie należy utworzyć trzy pliki w tym katalogu za pomocą zwykłego edytora tekstu, takiego jak Notatnik.

Pierwszy plik, który utworzymy to wpb-tabber-widget.php. Będzie on zawierał kod HTML i PHP do tworzenia kart i własnego widżetu WordPress. Drugi plik, który utworzymy to wpb-tabber-style.css i będzie on zawierał styl CSS dla kontenera kart. Trzeci i ostatni plik, który utworzymy to wpb-tabber. js, który będzie zawierał skrypt jQuery do przełączania kart i dodawania animacji.

Zacznijmy od pliku wpb-tabber-widget.php. Celem tego pliku jest utworzenie wtyczki rejestrującej widżet. Jeśli po raz pierwszy tworzysz widżet WordPress, zalecamy zapoznanie się z naszym przewodnikiem dotyczącym tworzenia własnego widżetu WordPress lub po prostu skopiowanie i wklejenie tego kodu do pliku wpb-tabber-widget.php:

<?php
/* Plugin Name: WPBeginner jQuery Tabber Widget
Plugin URI: https://www.wpbeginner.com
Description: A simple jquery tabber widget.
Version: 1.0
Author: WPBeginner
Author URI: https://www.wpbeginner.com
License: GPL2
*/

// creating a widget
class WPBTabberWidget extends WP_Widget {

function WPBTabberWidget() {
		$widget_ops = array(
		'classname' => 'WPBTabberWidget',
		'description' => 'Simple jQuery Tabber Widget'
);
$this->WP_Widget(
		'WPBTabberWidget',
		'WPBeginner Tabber Widget',
		$widget_ops
);
}
function widget($args, $instance) { // widget sidebar output

function wpb_tabber() { 

// Now we enqueue our stylesheet and jQuery script

wp_register_style('wpb-tabber-style', plugins_url('wpb-tabber-style.css', __FILE__));
wp_register_script('wpb-tabber-widget-js', plugins_url('wpb-tabber.js', __FILE__), array('jquery'));
wp_enqueue_style('wpb-tabber-style');
wp_enqueue_script('wpb-tabber-widget-js');

// Creating tabs you will be adding you own code inside each tab
?>

<ul class="tabs">
<li class="active"><a href="#tab1">Tab 1</a></li>
<li><a href="#tab2">Tab 2</a></li>
<li><a href="#tab3">Tab 3</a></li>
</ul>

<div class="tab_container">

<div id="tab1" class="tab_content">
<?php 
// Enter code for tab 1 here. 
?>
</div>

<div id="tab2" class="tab_content" style="display:none;">
<?php 
// Enter code for tab 2 here. 
?>
</div>

<div id="tab3" class="tab_content" style="display:none;">
<?php 
// Enter code for tab 3 here. 
?>
</div>

</div>

<div class="tab-clear"></div>

<?php

}

extract($args, EXTR_SKIP);
// pre-widget code from theme
echo $before_widget; 
$tabs = wpb_tabber(); 
// output tabs HTML
echo $tabs; 
// post-widget code from theme
echo $after_widget; 
}
}

// registering and loading widget
add_action(
'widgets_init',
create_function('','return register_widget("WPBTabberWidget");')
);
?>

.

W powyższym kodzie najpierw utworzyliśmy wtyczkę, a następnie wewnątrz tej wtyczki utworzyliśmy widżet. W sekcji wyjściowej widżetu dodaliśmy skrypty i arkusz stylów, a następnie wygenerowaliśmy dane wyjściowe HTML dla naszych kart. Na koniec zarejestrowaliśmy widżet. Pamiętaj, że musisz dodać treść, którą chcesz wyświetlić na każdej karcie.

Teraz, gdy utworzyliśmy widżet z kodem PHP i HTML potrzebnym dla naszych kart, następnym krokiem jest dodanie jQuery, aby wyświetlić je jako karty w kontenerze kart. Aby to zrobić, należy skopiować i wkleić ten kod do pliku wp-tabber.js.

(function($) {
$(".tab_content").hide();
$("ul.tabs li:first").addClass("active").show();
$(".tab_content:first").show();
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active");
$(this).addClass("active");
$(".tab_content").hide();
var activeTab = $(this).find("a").attr("href");
//$(activeTab).fadeIn();
if ($.browser.msie) {$(activeTab).show();}
else {$(activeTab).fadeIn();}
return false;
});
})(jQuery);

.

Teraz nasz widżet jest gotowy z jQuery, ostatnim krokiem jest dodanie stylizacji do kart. Stworzyliśmy przykładowy arkusz stylów, który można skopiować i wkleić w pliku wpb-tabber-style.css:


ul.tabs { 
position: relative; 
z-index: 1000; 
float: left; 
border-left: 1px solid #C3D4EA; 
}
ul.tabs li {
position: relative; 
overflow: hidden; 
height: 26px; 
float: left; 
margin: 0; 
padding: 0; 
line-height: 26px; 
background-color: #99B2B7;
border: 1px solid #C3D4EA; 
border-left: none; 
}
ul.tabs li  a{ 
display: block; 
padding: 0 10px; 
outline: none; 
text-decoration: none;
}
html ul.tabs li.active, 
html ul.tabs li.active a:hover { 
background-color: #D5DED9; 
border-bottom: 1px solid #D5DED9; 
}
.widget-area .widget .tabs a  { 
color: #FFFFFF; 
}
.tab_container {
position: relative; 
top: -1px; 
z-index: 999; 
width: 100%; 
float: left; 
font-size: 11px; 
background-color: #D5DED9; 
border: 1px solid #C3D4EA;
}
.tab_content { 
padding: 7px 11px 11px 11px;
line-height: 1.5;
}
.tab_content ul { 
margin: 0;
padding: 0; 
list-style: none; 
}
.tab_content li { 
margin: 3px 0;
 }
.tab-clear {
clear:both;
}

.

To wszystko. Teraz wystarczy przesłać katalog wpbeginner-tabber-widget do katalogu /wp-content/plugins/ twojej witryny WordPress za pośrednictwem FTP. Alternatywnie możesz również dodać katalog do archiwum zip i przejść do Wtyczki ” Dodaj nowy w twoim obszarze administracyjnym WordPress. Kliknij kartę przesyłania, aby zainstalować wtyczkę. Po włączaniu wtyczki, przejdź do Wygląd ” Widżety, przeciągnij i upuść WPBeginner Tabber Widget na twój panel boczny i to wszystko.

Drag and drop WPBeginner Tabber Widget into your Sidebar

Mamy nadzieję, że ten poradnik pomógł ci stworzyć tabber jQuery dla twojej witryny WordPress. W przypadku pytań i uwag możesz zostawić komentarz poniżej lub dołączyć do nas na Twitterze lub Google+.

Ujawnienie: Nasze treści są wspierane przez czytelników. Oznacza to, że jeśli klikniesz na niektóre z naszych linków, możemy otrzymać prowizję. Zobacz jak WPBeginner jest finansowany, dlaczego to ma znaczenie i jak możesz nas wspierać. Oto nasz proces redakcyjny.

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.

Najlepszy zestaw narzędzi WordPress

Uzyskaj BEZPŁATNY dostęp do naszego zestawu narzędzi - zbiór produktów i zasobów związanych z WordPressem, które każdy profesjonalista powinien mieć!

Reader Interactions

26 komentarzyZostaw odpowiedź

  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. Nitish Chauhan says

    Hi,
    My plugin is activated but in the widget section it show „There are no options for this widget.” message.please tell me how to activate all the function and i want to create plugin like
    „jQuery(document).ready(function() {
    var wrapper = jQuery(„.input_fields_wrap”); //Fields wrapper
    var add_button = jQuery(„.add_field_button”); //Add button ID

    //initlal text box count
    jQuery(add_button).click(function(e){ //on add input button click
    e.preventDefault();
    //max input box allowed
    //text box increment
    jQuery(wrapper).prepend(’×’); //add input box

    jQuery(’.input_fields_wrap’).sortable();
    jQuery(’.input_fields_wrap’).disableSelection();

    });

    jQuery(wrapper).on(„click”,”.remove_field”, function(e){ //user click on remove text
    e.preventDefault(); jQuery(this).parent(’div’).remove();

    });

    });”

    my code of java script .please suggest if you have any solution.
    Thanks

  3. Nabam Rikam says

    I have inserted the plugins in the sidebar, but when i try to click it says there is no option for this plugin. And after we browse it in website, we see three blank tbs. Guide me here a little bro.

  4. Kunle says

    i want to place the plugin just created in a place in my page, and not in the side bars or footer.
    how do i do that, to place it anywhere in my web page

  5. Zadius says

    This is the second tutorial I have tried and for some reason the plugin file does not show up under the plugin directory on my site. I upload the file directly using FTP but when I log into my wordpress admin area nothing appears under the plugin’s tab. Please advise. Thank you.

    Update: I zipped the file and uploaded it via the wordpress plugin interface. The file does not appear in my plugin’s folder on my FTP interface so I have zero clue where it show’s up. But I got it installed so thanks!

  6. John says

    Thank you for the tutorial. However, I noticed that the title is missing when I add the widget to the widget area. How can I add the title space to input a title?

  7. Drazen says

    Hey

    Thanks for this. I was just wondering, how to add option, so that when I am viewing widget, I can simply paste links in it, in each tab?

    For example:
    Tab 1 (option to rename it in widget options)
    – Text box below it in widget options(so that I can add text, links etc.)

    Tab 2 (option to rename it in widget options)
    – Text box below it in widget options(so that I can add text, links etc.)

    Tab 3 (option to rename it in widget options)
    – Text box below it in widget options(so that I can add text, links etc.)

    Thanks

  8. Grant says

    It keeps giving me this error:

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

    Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING in /home/content/11/10826211/html/wp-content/plugins/wpbeginner-tabber-widget/wpb-tabber-widget.php on line 16

  9. Rahul says

    Thanks man you’re a genius. I was just going to buy a premium plugin from codecanyon and then found this guide.

  10. Jonathan says

    Why is it that when I install this plugin it is saying it needs to be updated, and the update is from a another developer & is over 3 years old?

        • Jonathan says

          This is the plugin that WordPress thinks it is & is trying to update it to. http://wordpress.org/plugins/tabber-widget/

          I just updated the plugin to version 2.0 & that (for whatever reason) got it to stop asking to update it to the other plugin. I’d try renaming & changing the other plugin info, but that was the only thing that seemed to work.

        • WPBeginner Support says

          The only reason we can think of is that you probably named the plugin file or folder to tabber-widget.php instead of wpb-tabber-widget.php which caused WordPress to confuse the plugin with this other one. The version trick is ok too until this other plugin releases 2.0+ :) so its bed to clear the confusion.

        • WPBeginner Support says

          We were unable to reproduce this. Do you have access to another WordPress site where you can try this, just to test that there is nothing wrong on your end?

  11. Doris says

    This kind of defeats the purpose of WordPress being dynamic, doesn’t it? Hard coding text into a widget? Is there a way to pull dynamic content from the database? Us noobs don’t have much coding experience ya know…One would think there is a plugin that would do this…

    • WPBeginner Support says

      This tutorial is aimed at intermediate level users and the goal here is to show them how to create a tabber widget. For beginner level users, there are several built in template tags that can dynamically generate content inside each tab. For example:

      Display a list of your WordPress pages:

      <ul>
      <?php wp_list_pages('title_li='); ?>
      </ul>
      

      Show Random Posts:

      <ul>
      <?php $posts = get_posts('orderby=rand&numberposts=5'); foreach($posts as $post) { ?>
      <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
      </li>
      <?php } ?>
      </ul>
      

      Show recent comments:

      <?php
      $args = array(
      	'status' => 'approve',
      	'number' => '5'
      );
      $comments = get_comments($args);
      foreach($comments as $comment) :
      	echo($comment->comment_author . '<br />' . $comment->comment_excerpt);
      endforeach;
      ?>
      

      And many more.

      Administrator

  12. Grant says

    What I don’t understand is where to paste the code. What type of document do I put the code in? (I have mac).

  13. Jim Davis says

    Installed the files and activated the widget. It displays as expected, however, clicking the Tab 2 and Tab 3 tabs does not change the content. The content remains as the content under Tab 1. Have I missed something? See my test site at http://jimdavis.org/blog/

    Jim

    • WPBeginner Support says

      Jim you have not missed any thing. This is an example widget and you can edit it. Enter your own code and content inside each tab by editing the plugin file wpb-tabber-widget.php

      Administrator

Zostaw odpowiedź

Dziękujemy za pozostawienie komentarza. Pamiętaj, że wszystkie komentarze są moderowane zgodnie z naszymi polityka komentarzy, a Twój adres e-mail NIE zostanie opublikowany. NIE używaj słów kluczowych w polu nazwy. Przeprowadźmy osobistą i konstruktywną rozmowę.