I have the following dynamic output generated by Joomla for page navigation.
<ul>
<li class="pagination-start">
<span class="pagenav">Start</span>
</li>
<li class="pagination-prev">
<span class="pagenav">Prev</span>
</li>
<li>
<span class="pagenav">1</span>
</li>
<li>
<a title="2" href="link-to-page-2" class="pagenav">2</a>
</li>
<li class="pagination-next">
<a title="Next" href="link-to-next-page" class="pagenav">Next</a>
</li>
<li class="pagination-end">
<a title="End" href="link-to-last-page" class="pagenav">End</a>
</li>
</ul>
I need only the link data of the next page i.e. link-to-next-page which is wrapped by <li class="pagination-next"></li>
I need to do it in PHP so that I can make use of the same the same for my Infinite Scrolling plugin.
I can do it through jQuery but it will not serve the purpose. I am looking for a PHP solution to get this.
Can someone please help me?
Use the following in your jquery code:
navSelector : '.pagenav', // selector for the paged navigation
nextSelector : '.pagenav a[title="Next"]', // selector for the NEXT link (to page 2)
I have not debugged the above code, simply adapted it from Joomla 1.5 (see here)
Related
I wonder how to define template for each level in pdoMenu params if I want to make multilevel menu on my webpage?
For example the structure for menu is something like this:
<ul>
<li>
<div></div>
<img src="assets/img/1.png" />
<a>Link 1</a>
<ul>
<li>
<a>Sub link 1</a>
</li>
<li>
<a>Sub link 2</a>
</li>
</ul>
</li>
<li>
<div></div>
<img src="assets/img/2.png" />
<a>Link 2</a>
<ul>
<li>
<a>Sub link 1</a>
</li>
<li>
<a>Sub link 2</a>
</li>
</ul>
</li>
</ul>
As you can see first level of menu includes div and img tags but second does not.
That is why I need to define different templates via pdoMenu.
Unfortunately, there is no comprehensive examples for pdoMenu parameters.
It seems that pdoMenu provides this feature only for "&levelClass" parameter which gives incrementation for css class for each level.
May be I should use some other approach for this purpose? Pdoresources or getresources?
Wayfinder does have some menu template options you could explore: https://docs.modx.com/extras/evo/wayfinder#Wayfinder-TemplateParameters
But, for the time being, the only way I could think to do this would be to use getResources.
For your first level you would use a simple getResources call that restricts it to 1 level of depth, but in that .tpl you would have a 2nd getResources call.
For example:
[[!getResources?
&parents=`1`
&depth=`1`
&tpl=`firstLevel`
]]
Then firstLevel would look something like:
<li>
[[+pagetitle]]
[[!getResources?
&parents=`[[~[[+id]]]]`
&depth=`0`
&tplWrapper=`menuWrapper`
&tpl=`secondLevel`
]]
</li>
menuWrapper would just wrap secondLevel and look like:
<ul>[[+output]]</ul>
secondLevel would just look like:
<li>
[[+pagetitle]]
</li>
This is one way to go about it. The above is untested so you might want to keep that in mind.
As a side note, if you only want to add images you can use css, eg:
li ul li:first-child:before {
content: url('../images/image.png');
}
Hi I am working with a app where I get the Codeigniter Pagination through ajax. Problem is on every response, by default Page 1 is selected.
I am trying to replace the current class with $("#user_pagination ul.pagination li").removeClass("current"); which works fine but problem is to set the current class to the current page. I've the variable index which has the current page number, now if I had a class with page number like <li class='2'><a herf="#">2</a></li>, it would be very easy for me to add the current class.
Is there any way to do that using CodeIgniter Pagination class?
This is example of my html
<ul class="pagination pagination-sm m-t-none m-b-none">
<li class="current"> 1 </li>
<li> 2 </li>
<li class="next"> <i class="" title="Next">ยป</i>
</li>
</ul>
If there is any way to select the target <li> which has string 2 inside its child <a>, and addClass to that <li>? That would also solve the problem.
If i understand you right, this code can help you find tag <li> which has string 2 inside its child <a>:
$("#user_pagination ul.pagination li a:contains('2')").parent('li')
In TYPO3 I used html blocks which contains a nav of hash-tags
<li class="navbox default">
About us
</li>
<li class="navbox default">
Shop
</li>
<li class="navbox default">
Images
</li>
<li class="navbox default">
News
</li>
<li class="navbox default">
Sale
</li>
<li class="navbox default">
Contact us
</li>
This nav is used for Bootstraps Scroll-Spy and the hash-tags represent content-elements. Everything works fine, but only for the page "/". If I open the page in another language like /de.html or /en.html, TYPO3 prepend this part to the href and I get something like this
About us
This is fine for most cases, but Bootstraps Scroll-Spy expect all links as a "pure" Hash without anything in front.
My question is now, how can I disable TYPO3 parsing of html blocks/link replacement? I don't want to modify the bootstrap js files
config.prefixLocalAnchors = 0 is your friend if it is compatible to the rest of your environment (e.g. RealURL configuration):
http://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Config/Index.html?highlight=prefixlocalanchors
I just want to ask if what would I do to transfer the class attribute "active" based on the page I visit on my site.
For example [Bootstrap snippet]:
<ul class="nav nav-pills">
<li class="active">Home</li>
<li>Profile</li>
<li>Messages</li>
</ul>
So if I visit profile, the class is transferred into the <li> tag of Profile.
Try this
<ul class="nav nav-pills">
<li <?php if($_SERVER['REQUEST_URI']=='/index.php'){ ?> class="active" <?php } ?>>Home</li>
<li <?php if($_SERVER['REQUEST_URI']=='/profile.php'){ ?> class="active" <?php } ?>>Profile</li>
<li <?php if($_SERVER['REQUEST_URI']=='/message.php'){ ?> class="active" <?php } ?>>Messages</li>
</ul>
//we are taking demo php file like index.php,profile.php,message.php. you can use your own
Hope it will help
If you don't mind using Javascript on your site, Bootstrap has some built-in functionality to do this for you. Just make sure you have targets with resolvable id's (such as <div id="home">).
The biggest issue I run into with this design is that all of your "pages" are rendered at load. I find myself having to use a lot of AJAX if I am building anything that changes based on user input.
From the bootstrap site:
Markup
You can activate a tab or pill navigation without writing any JavaScript by simply specifying data-toggle="tab" or data-toggle="pill" on an element. Adding the nav and nav-tabs classes to the tab ul will apply the Bootstrap tab styling.
<ul class="nav nav-tabs">
<li>Home</li>
<li>Profile</li>
<li>Messages</li>
<li>Settings</li>
</ul>
I'm using Bootstrap nav-tabs/dropdown menus component as my primary navigation bar but I cant figure out how to set the active menu based on an incoming URI.
There are a lot of different examples/posts on the net that use nav-tabs for hiding and displaying specific div content or working with the # symbol but I just want to read the incoming URI using PHP, the _SERVER["REQUEST_URI"] variable and set a tab active. Be it a nested location in the navigation or not is also a problem.
Here what I've been trying:
<ul class="nav nav-tabs" id="supernav">
<li class="active"><i class="icon-home" style="margin-top:4px;"></i> Page 1</li>
<li class="dropdown">
Page 2 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Home</li>
<li class="divider"></li>
<li>Page 2.2</li>
<li>Page 2.3</li>
</ul>
</li>
<li class="dropdown">
Page 3 <b class="caret"></b>
<ul class="dropdown-menu">
<li>Home</li>
<li class="divider"></li>
<li class="dropdown-submenu">
Page 3.2
<ul class="dropdown-menu">
<li>Page 3.2.1</li>
<li>Page 3.2.2</li>
</ul>
</li>
</ul>
</li>
<li>Page 4</li>
</ul>
<script>
window.onload=function (e) {
e.preventDefault();
$('#supernav a[href="<?=$_SERVER["REQUEST_URI"];?>"]').tab('show');
};
</script>
Here are a couple URI examples:
http://abc.com/page1.html
http://abc.com/page2.3.html
http://abc.com/page3.2.2.html
Can anyone point me to a good example of how to accomplish this or am I just asking too much from this component?
NOTE: I've preloaded all the bootstrap and jquery resources in my header.
I'm a little late to the party but just came across this post and I figured I'd add my extra 2 cents...
Basically, the best method I've found to set the active bootstrap's tab/pill is by using Javascript/jQuery to match the current url to the href of the active link.
So if your menu is set up as the following:
<ul class="nav nav-tabs">
<li>Page 1</li>
<li>Page 2</li>
</ul>
Your jQuery will be:
$(document).ready(function() {
$('.nav-tabs a[href="'+location.href+'"]').parents('li').addClass('active');
});
This assumes absoulte path for the link's href, but that could be easily overriden by something like:
$(document).ready(function() {
var url_parts = location.href.split('/');
var last_segment = url_parts[url_parts.length-1];
$('.nav-tabs a[href="' + last_segment + '"]').parents('li').addClass('active');
});
Hope this helps somebody in the universe! :)
Cheers!
I've solved my own problem, here is a recap of the goal and what it took to accomplish.
Goals:
I wanted to use the bootstrap nav-tabs component for my navigation
bar because I liked the look/feel of it better.
I wanted to be able to set the 'active' class by parsing the
incoming URI.
I wanted sub-navigation to work as well.
New code based on first post:
<ul class="nav nav-tabs" id="supernav">
<li id="page1"><i class="icon-home" style="margin-top:4px;"></i> Page 1</li>
<li class="dropdown" id="page2">
Page 2 <b class="caret"></b>
<ul class="dropdown-menu">
<li id="page2_home">Home</li>
<li class="divider"></li>
<li id="page2_2">Page 2.2</li>
<li id="page2_3">Page 2.3</li>
</ul>
</li>
<li class="dropdown" id="page3">
Page 3 <b class="caret"></b>
<ul class="dropdown-menu">
<li id="page3_home">Home</li>
<li class="divider"></li>
<li class="dropdown-submenu" id="page3_2">
Page 3.2
<ul class="dropdown-menu">
<li id="page3_2_1">Page 3.2.1</li>
<li id="page3_2_2">Page 3.2.2</li>
</ul>
</li>
</ul>
</li>
<li id="page4">Page 4</li>
</ul>
Notice in the code above that there are no
class="active"
or
data-toggle="tab"
set anywhere.
Because I wanted to make my nav on a static template which is used as a header for all templates I couldn't add any dynamically generated code based on incoming URI's but it turns out not to be necessary.
I added the following Javascript code to bottom of each template a visitor calls to help tell the nav-list which items to be marked as 'active'.
I used this script at the bottom of my /page1.html
<script type="text/javascript">
window.onload=function () {
$('#page1').addClass('active');
};
</script>
To set /page3.2.2.html as the active page and all the nav lvls above it I did this
<script type="text/javascript">
window.onload=function () {
$('#page3').addClass('active');
$('#page3_2').addClass('active');
$('#page3_2_2').addClass('active');
};
</script>
Now when a user comes to my site the nav gets loaded from a static file and the rest of the page contains the dynamic JavaScript that sets what components I want set active.
I also found it necessary to make this one little modification to my custom css in order to make sure no line appeared under my 'active' tab, just a visual thing probably needed because of my font settings.
.nav-tabs > li { margin-bottom: -3px; }
I would have posted some SS's but my 'rep' isn't above 10 yet, ha ha ha. Hopefully this helps someone else, god help us all when version 3 of bootstrap comes out and we have to figure this all out again. 8^)P
Tab is set active on the client-side, not on the server. This is because, usually all the contents of each tab are actually there already in the document on page load. Clicking on a tab simple hides one tab and then shows the tab having the id which the anchor element links to.
Here's what the simplest implementation of Bootstrap's tab looks like:
<!-- tab navigation -->
<ul class="nav nav-tabs">
<li class="active">
Home
</li>
<li>...</li>
<li>...</li>
</ul>
<!-- tab contents are inside -->
<div class="tab-content">
<!-- content of each tab is put inside a tab-pane or tab-pill -->
<div class="tab-pane active" id="tab1">
<p>content of tab 1</p>
</div>
<div class="tab-pane" id="tab2">
<p>content of tab 2</p>
</div>
<div class="tab-pane" id="tab2">
<p>content of tab 3</p>
</div>
</div>
That's not all, you still need to activate tabbing using JS like this:
$('ul.nav.nav-tabs > li > a').click(function(e) {
e.preventDefault();
$(this).tab('show');
});
Based on how your question is constructed, I think you should go have a better look at what each Bootstrap component stands for, and try to understand what are their appropriate use-case.
If your aim was to show a specific tab in response to a request. Simply add the 'active' class to the div element that wraps its content.
And then make it show by doing this:
$('tab-pane active').tab('show');
Note: all you have to do is add active in the right place each time.
For you case specifically, the problem is in your jQuery. Here's the correct way to write it:
$('#supernav active').tab('show');
I was facing similar problem while I had few page urls like : www.somedomain.com/pages/xyz/abc/samplepage.html
This code worked in my case like magic.
$(document).ready(function() {
var permalink_nodomain = window.location.pathname;
$('.nav-tabs a[href="' + permalink_nodomain + '"]').parents('li').addClass('active');
});
May be someone is still looking for this solution just like me :)
Using PHP to set the active isn't the ideal way as PHP is server-side code and the bootstrap is a client-side UI. I recently had a project using bootstrap and found the same issue quite annoying given how powerful bootstrap is and truly hope they fix this in the upcoming 3.0 release.
The way I fixed it was to use jquery to reference a unique id on the link tag and update the active tab value based on that.
So really all the jquery did was remove the active class and assign it to the current clicked link.
If you still want to use the URL path than I'd suggest you use javascript/jquery over PHP. Check out this article on how to do just that. http://css-tricks.com/snippets/javascript/get-url-and-url-parts-in-javascript/
Hope that helps.
Using Bootstrap 4
Given (HAML)
%nav.nav.nav-pills.flex-column
%a.nav-link.active{href: '#users', 'data-toggle'=>'pill', role: 'tab'} Users
%a.nav-link{href: '#deals', 'data-toggle'=>'pill', role: 'tab'} Deals
%a.nav-link{href: '#facilitators', 'data-toggle'=>'pill', role: 'tab'} Facilitators
This is reduced to (Coffeescript)
if location.hash
$('nav.nav-pills a[href="'+location.hash+'"]').tab('show')
Doc: http://v4-alpha.getbootstrap.com/components/navs/#via-javascript