Link to Specific Bootstrap Tab From Another Page Wordpress - wordpress

I'm using bootstrap tab shortcodes on my Wordpress site. I want to link from another page to tab2. Can anyone advise how this is done?
My page code (chopped a bit):
[bootstrap_tab name="TAB1" link="tab1-slug" active="active"]
TAB 1 Content
[/bootstrap_tab]
[bootstrap_tab name="TAB2" link="tab2-slug"]
More content
[/bootstrap_tab]
[bootstrap_tab name="TAB3" link="tab3-slug"]
Yep. Even more content.
[/bootstrap_tab]
[bootstrap_tab name="TAB4" link="tab4-slug"]
Yep. Even more content.
[/bootstrap_tab]
[end_bootstrap_tab]
The code it produces:
<ul id="tabs" class="nav nav-tabs" data-tabs="tabs">
<li class="tabs active">
<a data-toggle="tab" href="#tab1-slug">TAB1</a>
</li>
<li class="tabs ">
<a data-toggle="tab" href="#tab2-slug">TAB2</a>
</li>
<li class="tabs ">
<a data-toggle="tab" href="#tab3-slug">TAB3</a>
</li>
<li class="tabs ">
<a data-toggle="tab" href="#tab4-slug">TAB4</a>
</li>
</ul>
<div id="my-tab-content" class="tab-content">
<div id="tab1-slug" class="tab-pane active">
<p></p>
<h2>header</h2>
<p><strong>bold</strong></p>
<p>content</p>
<p></p>
</div>
<div id="tab2-slug" class="tab-pane ">
<p></p>
<h2>TAB2</h2>
<p><strong>These are usually two day</strong></p>
</div>
<div id="tab3-slug" class="tab-pane ">
<p></p>
<h2>TAB3</h2>
<p>1 to 2 day events</p><p></p>
</div>
<div id="tab4-slug" class="tab-pane ">
<p>
<h2>TAB4</h2>
<p><strong>5 to 10 day courses</strong></p>
</div>
</div>

Though not in WordPress, this seems to be the definitive solution to linking to Bootstrap tabs:
Twitter Bootstrap Tabs: Go to Specific Tab on Page Reload or Hyperlink
That being said, I wrote a WordPress plugin that will do this. Activate the plugin, then you'll be able to use the tab's href as the hash.
If your tab looks like this:
<li>Profile</li>
You can link to it and activate/open it using a link like this:
Link to my tab
The plugin will also allow you to link directly to content on the tabs, using a sort of a two-step link:
Step 1 Activate the proper tab
Step 2 Scroll to the content on the tab.
It does this using only a single hash in the URL.
For example: http://www.example.com/mypage/#content
This will take you to "mypage" and the HTML element with id="content", whether it's on an active/inactive Bootstrap tab or just on the page somewhere.
Hope this helps:
Here's the plugin on GitHub: https://github.com/marinersmuseum/WP-Tab-Anchors/blob/master/wp-tab-anchors.zip

Supposing that jQuery is being loaded and that the link URL is something like
http://example.com/page-with-tabs/?tab=NUMBER
We print some conditional script at the footer:
add_action( 'wp_footer', 'active_tab_so_19576232' );
function active_tab_so_19576232()
{
# Query var not set in URL, bail out
if( !isset( $_GET['tab'] ) )
return;
# Change the active tab
$tab = '#tab'. $_GET['tab'] .'-slug';
?>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('div.tab-pane.active').removeClass('active');
$('<?php echo $tab; ?>').addClass('active');
});
</script>
<?php
}
Should be a plugin, but you can drop the code in your theme functions.php.

Related

Wordpress short-code content disappears in tabs upon clicking them in mobile view

I am using this code and it works on my Wordpress and Elementor site great:
https://codepen.io/mooku/pen/BQZQwO
<div class="tabs-container">
<nav class="tabs">
<ul>
<li class="active" data-tab="tab-1">Sports</li>
<li data-tab="tab-2">Monogram</li>
<li data-tab="tab-3">Holiday</li>
</ul>
<div id="tab-1" class="tab-content current">
[product_category category="sports" per_page="9" columns="4" orderby="date" order="desc" operator="AND"]
</div>
<div id="tab-2" class="tab-content">
[product_category category="monograms" per_page="9" columns="4" orderby="date" order="desc" operator="AND"]
</div>
<div id="tab-3" class="tab-content">
[product_category category="holiday" per_page="9" columns="4" orderby="date" order="desc" operator="AND"]
</div>
$(document).on('click', 'li', function(){
$('li').removeClass('active');
$('ul').toggleClass('expanded');
$(this).addClass('active');
var tab_id = $(this).attr('data-tab');
$('.tab-content').removeClass('current');
$(this).addClass('current');
$('#'+tab_id).addClass('current');
});
I put shortcodes in each tab so I can show my Woocommerce products by category. For some reason however when viewing it in mobile view as a condensed drop down, when I click on a product within a tab, the entire tab's content disappears, the dropdown menu expands, and is covered by content below it briefly before proceeding to the clicked products page. Everything is working besides that annoying error. I should note I did a test where I took out the shortcode and just put up links, and upon clicking those everything works fine, so the shortcodes are definitely to blame. Any way to fix this?
Before Clicking
After Clicking

Pagination Wordpress in Custom Plugin ( Javascript )

Hi I hope someone can help with this. I'm building a wordpress plugin. I just have basic knowledge of php and i managed to build the whole plugin except pagination. I have tried so many code using javascript but none is working for me. Here is the image. I want to divide the items with pagination
Thank you in advance!
A good approach will be to think about the pages like tabs. Then the page link will behave like buttons that show/hide based on the page link clicked.
Here's an example using jQuery
// Add an event listener for when the page link is clicked
$('.page-link').on('click', function(){
// Save the page number that was clicked
var pageNum = $(this).data('page-id')
// Hide any open 'pages'
$('.page-content').hide();
// Find and show the selected page
$('[data-page=' + pageNum + ']'').show();
});
For this to work, you'd need a HTML structure a bit like this
<!-- The Page Link -->
<div>
<ul>
<li class="page-link" data-page-id="1">Page 1</li>
<li class="page-link" data-page-id="2">Page 2</li>
<li class="page-link" data-page-id="3">Page 3</li>
</ul>
<!-- The Page Content -->
<div class="page-content" data-page="1" style="display: none;">
Page 1 content
</div>
<div class="page-content" data-page="2" style="display: none;">
Page 2 content
</div>
<div class="page-content" data-page="3" style="display: none;">
Page 3 content
</div>
</div>
Here is a super basic jsfiddle

Orchard CMS: Modifying a menu item alternate and iterating over the items

Let's say I created a menu titled "Main Menu" from the admin panel and I need to customize the default markup, e.g. let's say I want to modify/replace the <ul>, <li> as well as the surrounding <article> and <nav> tags.
I assume that I have to come up with something like this in my Parts.MenuWidget.cshtml alternate template.
<ul class="a b c">
for each item in menuItems:
display("<li>" + item + "</li>")
end
</ul>
How do I do that in Orchard?
That's quite simple.
You could first create an alternate for you MenuWidget like so:
Parts.MenuWidget-MyZoneName.cshtml
<nav>
<div class="logo">
#Html.Partial("_Logo")
</div>
<ul>
#*Display all the stuff added in the admin*#
#DisplayChildren(Model.Menu)
#*Add additional stuff. Of course you could also add it as MenuItem to the Menu-Model*#
#if ( Request.IsAuthenticated )
{
if ( Authorizer.Authorize(StandardPermissions.AccessAdminPanel) )
{
<li>
<a href="/Admin">
Admin
</a>
</li>
}
<li>
<a href="~/Example1">
Extra1
</a>
</li>
}
else
{
<li>
<a href="~/Example2">
Extra2
</a>
</li>
}
</ul>
</nav>
And then go on and do something similar for your MenuItems. For example:
MenuItemLink.cshtml
#Model.Text
Another thing that's worth mentioning is that you can either only provide an alternate for a specific shape like the MenuItemLink above or just provide an alternate for the base MenuItem shape which will then be used for every MenuItem type that exists.
(Maybe those are not the best examples, but I guess they'll do the job ;) )
Update:
In order to remove/modify the tags you can create an alternate for MenuItem.cshtml and look at this part:
if (HasText(renderedMenuItemLink))
{
var tag = Tag(Model, "li");
#tag.StartElement
#renderedMenuItemLink
if (items.Any())
{
<ul>
#DisplayChildren(Model)
</ul>
}
#tag.EndElement
}

How do I fix Zurb Foundation dropdown issue on mobile devices?

Here's the code I used:
<div style="top-buttons">
<img src="images/sandwich.gif" class="sandwich" width="30" height="30">
</div>
<ul id="tinyDrop" class="f-dropdown" data-dropdown-content>
<hr>
<li class="navitem"><img src="images/group-25.png"/> Trends / Activity</li>
<hr>
<li class="navitem"><img src="images/settings2-25.png"/> Settings</li>
<hr>
<li class="navitem"><img src="images/help-25.png"/> Help</li>
<hr>
<li class="navitem"><img src="images/star-25.png"/> Rate Clustir</li>
<hr>
<li class="navitem"><img src="images/exit-25.png"/> Logout</li>
<hr>
</ul>
I also tried specifying a class (open) which is supposed to be added when the user taps/clicks the button:
<script>
$(document).foundation({
// specify the class used for active dropdowns
active_class: 'open'
});
</script>
with the following css to see if this class can even do anything. It looks like it's not even being utilized.
.open{
display:none;
}
Any ideas how I can fix this probably with jquery or a better css. I hope this is not a Foundation bug.
Are you on Foundation 5? I noticed after upgrading from 4 to 5 that you need the "data-dropdown-init" attribute on the parent element as shown below
<img src="images/sandwich.gif" class="sandwich" width="30" height="30">
Without the above modification, I see javascript errors in the console complaining about undefined properties in foundation.dropdown.js.

Wordpress shows additional category text

I am developing WP website and stuck in side bar category showing functionality.
Here is my code.
<div class="sidebarcategory">
<h2 class="widgettitle"><?php echo get_cat_name(3); ?></h2>
<ul>
<li>
<?php wp_list_categories('hide_empty=0&orderby=name&child_of=3&feed_image=http://devsites.dyndns.info/novelty/wp-content/themes/pixel/images/icon-car.png'); ?>
</li>
</ul>
</div>
So, this display me Additional "Category" over the top of the list which i don't require. Can anybody help me to remove out in dynamic code. Output looks like
<ul>
<li>
</li><li class="categories">Categories<ul> <li class="cat-item cat-item-4">
add a emty parameter title_li
wp_list_categories('title_li=&hide_empty=0&orderby=name&child_of=3&feed_image=http://devsites.dyndns.info/novelty/wp-content/themes/pixel/images/icon-car.png');

Resources