WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Section Widget] Keep same tab when switching pages (5 posts)

  1. RichTWebGuy
    Member
    Posted 4 years ago #

    I made a section-widget with two tabs. When I switch pages section-widget always returns to first tab. Change this be changed?

    Tab 2 shows a list of posts. Visitor clicks on first post, that page is displayed, then when they go to click on second post, section-widget is showing tab 1.

    http://wordpress.org/extend/plugins/section-widget/

  2. godfreykfc
    Member
    Posted 4 years ago #

    You might want to check this out: http://jqueryui.com/demos/tabs/#option-cookie (Warning: JavaScript/jQuery ahead..)

  3. Gravitydk
    Member
    Posted 4 years ago #

    I think you refer to this code element as the solution, yes?
    http://jqueryui.com/demos/tabs/#...immediately_select_a_just_added_tab

    in which case, we stick that code within the plugin source code as instructed there?

  4. Gravitydk
    Member
    Posted 4 years ago #

    I worked out, with help of my own site reader, that this is the code to insert. I'm not sure into which file to put it into?

    var $tabs = $('#example').tabs();
    var selected = $tabs.tabs('option', 'selected'); // => 0
  5. godfreykfc
    Member
    Posted 4 years ago #

    Hi, what you want to do is actually kind of complicated. In order to make a tab "stay selected" between different pages, you'd have to store that value somewhere in a browser cookie. The example you linked from above is for a different task, and the code you pasted in your last post is for reading the current selected tab's ID, but it doesn't store it anywhere or use it in any meaningful way.

    To do what you need, you'll need to load jquery.cookies.js (Download it from here). And then you can add the following code in your theme JavaScript file:

    jQuery('.swt-wrapper').tabs('option', 'cookie', { expires: 30 });

    If you are not too comfortable with doing all that, I'd advise you to leave it as is unless the feature is mission critical to your site.

    Godfrey

Topic Closed

This topic has been closed to new replies.

About this Topic