how to use the dynamic PHP ajax data with the bootpag - php

How can I display the dynamic content of PHP with bootstrap pagination.The result is displaying using ajax call in div id 'msrResult', how to use that div in bootstrap pagination code. Here my code:
<script src="//code.jquery.com/jquery-2.0.3.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="//raw.github.com/botmonster/jquery-bootpag/master /lib/jquery.bootpag.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
</head>
<div id="content2">Dynamic Content goes here</div>
<div id="page-selection">Pagination goes here</div>
<script>
$('#page-selection').bootpag({
total: 23,
page: 1,
maxVisible: 10
}).on('page', function(event, num){
$("#content2").html("Page " + num); // or some ajax content loading...
});
</script>
</body>
</html>
<div id=msrResult></div>

First of all the "space" in the GitHub URL could produce 404 responses. You should delete it to get the script working ;)
Basically (as you can see at the authors website) clicking the page-buttons (they are showing up in #page-selection once the script is initialized correctly) triggers bootpag to toggle the content. In the .on() function you have the chance to place new content right before it shows up again.
In the script you've provided you write "Page X" in #content2 before it shows up. But in your case you want to load dynamic content in this div so you could do something like this:
$.ajax({
url: "source.php?site="+num
}).done(function(data) {
$( "#content2" ).html( data );
});
in the .on() function to load the dynamic php content in your #content2 div
Also see this JS fiddle for a demo: http://jsfiddle.net/628zL/3/

U can easily do that by this way-
$('#show_paginator').bootpag({
total: 23,
page: 3,
maxVisible: 10
}).on('page', function(event, num)
{
$("#dynamic_content").html("Page " + num); // or some ajax content loading...
});
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://botmonster.com/jquery-bootpag/jquery.bootpag.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<div id="dynamic_content">Pagination goes here</div>
<div id="show_paginator"></div>
If u like to use customised version, then u can try this-
$('#show_paginator').bootpag({
total: 53,
page: 2,
maxVisible: 5,
leaps: true,
firstLastUse: true,
first: '←',
last: '→',
wrapClass: 'pagination',
activeClass: 'active',
disabledClass: 'disabled',
nextClass: 'next',
prevClass: 'prev',
lastClass: 'last',
firstClass: 'first'
}).on('page', function(event, num)
{
$("#dynamic_content").html("Page " + num); // or some ajax content loading...
});
<script src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://botmonster.com/jquery-bootpag/jquery.bootpag.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<div id="dynamic_content">Pagination goes here</div>
<div id="show_paginator"></div>
If u like to use more customization, u can try this options-
Warning
Here I am using a CDN (http://botmonster.com/jquery-bootpag/jquery.bootpag.js) for showing content. But it is not recommanded.
Hardly recommendation is to download this file and put it locally.
Because there is no official CDN for bootpeg.
Even more can be found from here.
I think u have your complete answer.

Related

How to open lightbox on clicking existing href link (wordpress)?

I need to open lightbox when clicking on href link.
I tried the following code but it doesn't open the lightbox (the url opens in the same browser).
Would you please let me know how to open lightbox?
Existing code (created by using DWQA plugin):
<div class="dwqa-questions-list">
<div class="dwqa-question-item dwqa-status-answered">
<header class="dwqa-question-title">
Question One
</header>
</div>
<div class="dwqa-question-item dwqa-status-answered">
<header class="dwqa-question-title">
Question Two
</header>
</div>
</div>
Lightbox code I tried:
The console shows one error:
Unexpected token '<' => <!DOCTYPE html>
?>
<script language="JavaScript" type="text/javascript" src="jquery/jquery.js"></script>
<script>
(function($){
$(document).ready(function() {
$("a", ".dwqa-question-title").click(
function(event) {
event.preventDefault();
var elementURL = $(this).attr("href");
$.colorbox({iframe: true, href: elementURL, innerWidth: 645, innerHeight: 509});
});
});
});
</script>
Thank you.

How to display a div block only on the main page on Datalife Engine?

I have a div block that I only want to display on the first page. I mean, if the user is on
http://mywebsite.com/
it displays the div. But if he navigates to the second page of the posts
http://mywebsite.com/page/2
it hides that div. I am using Datalife Engine.
Div example:
<div class="example"> This is a test </div>
Can this be done?
follow this and all be worked fine.
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if( $('#mainPage').length > 0 ) {
$("#hideMe").css({"display": "block"});
} else {
$("#hideMe").css({"display": "none"});
}
});//end doc ready function
</script>
</head>
<body>
<div id="mainPage"> </div>
<div id="hideMe">lorem ipsum</div>
</body>
hope it helps you
example http://jsfiddle.net/viktorino/56ea5/
For datalife engine, display just on the first page we use:
[page-count=1]Content goes here[/page-count]

Loading javascript on only one wordpress page

Below is my code. Not sure why this isn't working. I know it's not because when I use firebug on different pages that aren't page 39, it's saying fitvids() is not a function. So it's loading on every other page.
<?php if (is_page ( 39 )){?>
<script src="../js/jquery.fitvids.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#content-wrapper").fitVids();
});
</script>
<?php } ?>

div content change function not recognized

Hello & thanks for your time!
I'm trying to set up buttons for categories that when clicked load that categories first item in the vis Contained div. Then 'next' and 'prev' buttons in the loaded div data that switch to other items in that category.
So far I have:
php:
<nav>
<button onclick="changeContent('content1')">content1</button>
</nav>
<section id="main">
<div id="visContainer"><div>
</div>
</section
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="/js/jquery.min.js"><\/script>')</script>
<script src="js/javascript.js"></script>
js:
$(function(){
function changeContent(content){
$('#visContainer').load('divList.html' content);
};
});
along with a divList.html file that has different divs listed (filled w text for now).
I'm getting an 'Unexpected identifier' on the function changeContent line in the js and it keeps saying changeContent is not defined (when button clicked). I thought it may be something to do with my declaration or the jQuery but I can't figure out where. I'm new to this so any help would be much appreciated!
$(function(){ ... });
That function creates a new scope, making changeContent unavailable in the window scope where your inline event handler lives. Quick fix would be :
$(function(){
window.changeContent = function(content){
$('#visContainer').load('divList.html' content);
}
});
A better solution would be to remove the inline event handler.
<button id="myButton">content1</button>
and JS:
$(function(){
$('myButton').on('click', function() {
$('#visContainer').load('divList.html #content1');
});
});

Store an array in PHP between page calls

Suppose I have a page called view.php, if I give an argument like view.php?q=fruit, it creates a list of fruits stored in an array. I want change the content of a label in a page to be changed to the content of that array if a slider in that page changes. In the example above, this array contains: $list = array('banana', 'apple', 'orange'); I want to have a slider in the page and a lable that when the user changes the slider's value, the label's text changes to 'banana', 'apple', ...
I heard aboue sessions in PHP but since there may be lots of calls to this page in multiple tabs, I think this wouldn't be a good idea. How can I do this?
Thanks in advance.
It sounds like the only difference between different tabs would be the list that's generated. So your PHP code doesn't need to account for anything except which list you're going to be using. Here's a quick jquery mockup. With some CSS, and maybe some jquery animation, your slider could work without any page reloads at all.
<?php
$list = array(
'fruit' => array('apple','orange','banana'),
'soemthing' => array('a', 'b', 'c')
);
?>
<div id="Label">Click one of the list items to change this</div>
<ul id="Slider">
<?php foreach ($list[$_GET['q']] as $item) { ?>
<li><?php echo $item; ?></li>
<?php } ?>
</ul>
<script type="text/javascript">
$('#Slider li').click(function() {
$("#Label").text($(this).text());
// you can have some other logic here to decide what to do when the slider is changed
});
</script>
i think you can use a jquery solution .
store your array in your jquery code .
then call it on change function of your slider
like this ,
$('.slider').change(function(){
var index = $(this).index();
var label = labelsarray[index];
$('#label').data(label);
});
For slides I also do recommend jquery like others do, remember you can have asynch loads as well.
I don't remember the url but I had seen an amazing tutorial on jQuery with asynch load.
Some keywords: js asynch, image load jquery, jquery scroll
Try google with jquery scroll asynch it was an excellent tutorial with image loading asynchronously in many ways (by hovering, clicking, scrolling etc).
OK. I found what I wanted. I found a pretty neat slider here:
http://jqueryui.com/demos/slider/
then I used in in my page like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Slider - Snap to increments</title>
<link type="text/css" href="jquery/slider.css" rel="stylesheet" />
<script src="jquery/jquery-1.6.1.js"></script>
<script src="jquery/jquery-ui-1.8.13.custom.min.js"></script>
<?php
$list = array('apple','orange','banana');
?>
<script>
var arrayFromPHP = <?php echo json_encode($list) ?>;
$(function() {
$( "#slider" ).slider({
value:1,
min: 0,
max: arrayFromPHP.length - 1,
step: 1,
slide: function( event, ui ) {
$( "#amount" ).val(arrayFromPHP[ui.value]);
}
});
$( "#amount" ).val( arrayFromPHP[$( "#slider" ).slider( "value" )] );
});
</script>
</head>
<body>
<div class="demo">
<p>
<label for="amount">Current selection:</label>
<input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" />
</p>
<div id="slider"></div>
</div>
</body>
</html>
Please note that I used Rob's answer as my source and all the credit's go to him. But since it was not EXACTLY what I wanted, I decided to post my own answer.

Categories