pagination with bootstrap 4 cards - php

I'm creating a sort of blog area on my website using bootstrap 4 cards, i fill my cards with data from my database. And i want to put the cards inside of a pagination with a category filter
my category select is working fine, but I'm not sure how I'm supposed to tackle the part for calculating how many rows and columns are supposed to be on the webpage. I know i can make a variable which holds the maximum amount of rows and columns and calculate the offset from that with the ceil function. Then put that into a SQL query with the LIMIT being the offset and maximum items but I am not sure how this works with rows. this is the code i have at the moment. `
<nav aria-label="Page navigation example">
<ul class="pagination justify-content-center">
<li class="page-item disabled">
<a class="page-link" href="#" tabindex="-1">Previous</a>
</li><li class="page-item"><a class="page-link" href="blog.php?category=<?php if (isset($_GET["category"])){echo $_GET["category"];}?>&pagenumber=<?php // this is also where I'm stuck ?>">1</a>
</li>
<li class="page-item"><a class="page-link" href="blog.php?category=<?php if (isset($_GET["category"])){echo $_GET["category"];}?>&pagenumber=<?php // this is also where I'm stuck ?>">2</a></li>
<li class="page-item"><a class="page-link" href="blog.php?category=<?php if (isset($_GET["category"])){echo $_GET["category"];}?>&pagenumber=<?php // this is also where I'm stuck ?>">3</a></li>
<li class="page-item">
<a class="page-link" href="#">Next</a>
</li>
</ul>
</nav>
`
the category works so for example if i select category 2 the url will be
http://localhost/HCDistributie/blog.php?category=2&pagenumber=
the only thing that is needed is to get the pagenumber.
this is my back-end code where i loop through each each item in the database and put that inside the card
function getNews()
{
// get current category
if (isset($_GET["category"]) && is_numeric($_GET["category"])) {
// bind get category to categoryId
$categoryId = $_GET["category"];
// if category is 1
if ($categoryId == 1) {
if (isset($_GET["pagenumber"]) && is_numeric($_GET["pagenumber"])) {
$pageNumber = $_GET["pagenumber"];
try {
$itemLimits = 9;
$rowLimit = 3;
$db = new Connection();
$database = $db->openConnection();
$stm = $database->query("SELECT * FROM blog where category = $categoryId");
$stm->execute();
$rowNews = $stm->fetchAll(PDO::FETCH_ASSOC);
foreach ($rowNews as $items) {
?>
<div class="card-group">
<div id="classContainer" class="col-md-4">
<div class="card">
<img src=" <?php $items['img'] ?>" class="card-img-top" alt="...">
<div class="card-body">
<h5 class="card-title"><?php echo $items["title"]; ?></h5>
<p class="card-text"><?php echo $items["content"] ?></p>
<p class="card-text"><small
class="text-muted"><?php $items["author"]; ?></small>
</p>
</div>
</div>
</div>
</div>
<?php
}
} catch
(PDOException $e) {
echo sprintf("Something went wrong. $e->errorInfo");
}
}
}
}
}
I sort of have an idea what i should do the problem is I'm not sure how to apply that to my code, the tutorials i have read only deal with variable for max items while i have 2 max columns and max rows.
I am not sure how to calculate both of them separately.
This is the first time I worked with any sort of pagination so i apologize if some things seem weird and or stupid.

This is not weird or stupid, first contact with pagination is always a hassle ;)
With bootstrap, you could get away with just knowing the maximal occurrences of your card records. You could wrap everything while using rows and cols, check out this example:
<div class="container">
<div class="row">
<div class="col-4">
1 of 5
</div>
<div class="col-4">
2 of 5
</div>
<div class="col-4">
3 of 5
</div>
<div class="col-4">
4 of 5
</div>
<div class="col-4">
5 of 5
</div>
</div>
</div>
Fiddle
Thanks to .col-4, you will always get three cards in a row. In your example:
<div class="card-group">
<div class="row">
<?php foreach ($item as $items) { ?>
<div class="col-4">
<div class="card">
// Your card content goes here, use $item
</div>
</div>
<?php } ?>
</div>
</div>
More importantly, it seems you writing something in plain PHP. If you want to go public, you should consider a framework that has already some validation capabilities and function helpers - even build in pagination! I would pick Laravel for that.
EDIT:
Fixed mistake. Thanks #hakiko

Related

PHP Pagination not working when Records Filter is applied

I have written a PHP script which has option to filter records and display filtered records pagewise.
My Problem:
When I apply the filter, the records are displayed but when I click on any page number it displays all records page wise instead of showing filtered records pagewise.
How can I correct this?
Here is my complete script,
<body>
<form style="background-color:darkorange; font-size: 13px;" id="form1" name="form1" method="post" action="displaydesign.php">
<label>Design Category</label>
<select name="dlocation">
<option value="">All</option>
<?php
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." GROUP BY dlocation ORDER BY dlocation";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
while ($row = mysql_fetch_assoc($sql_result)) {
echo "<option value='".$row["dlocation"]."'".($row["dlocation"]==$_REQUEST["dlocation"] ? " selected" : "").">".$row["dlocation"]."</option>";
}
?>
</select>
<input type="text" name="string" id="string" value="<?php echo stripcslashes($_REQUEST["string"]); ?>" placeholder="Search by Name or City" />
<input type="submit" name="button" id="button" value="Filter" />
<a style="background-color:white;" href="displaydesign.php"> Reset</a>
</form>
<hr>
<?php
if ($_REQUEST["string"]<>'') {
$search_string = " AND (dname LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR dcity LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%')";
}
if ($_REQUEST["dlocation"]<>'') {
$search_dlocation = " AND dlocation='".mysql_real_escape_string($_REQUEST["dlocation"])."'";
}
$per_page=2; // no.of records per page
if (isset($_GET["page"])) {
$page = $_GET["page"];
}
else {
$page=1;
}
// Page will start from 0 and Multiple by Per Page
$start_from = ($page-1) * $per_page;
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE did>0".$search_string.$search_dlocation." order by did desc LIMIT $start_from, $per_page";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
if (mysql_num_rows($sql_result)>0) {?>
<div class="row">
<?php while ($row = mysql_fetch_assoc($sql_result)) { ?>
<div class="col-sm-6">
<div class="card" >
<h3 class="card-header card-success text-center"><?php echo $row['dlocation'] ?></h3>
<img class="card-img-top img-fluid" src="<?php echo $row['dimage'] ?>" alt="Card image cap">
<div class="card-block ">
<h4><span class="badge badge-default">Designer Information</span></h4>
<h5 class="card-title"><?php echo $row['dname'] ?></h5>
<h6 class="card-subtitle mb-2 text-muted "><?php echo ($row['dcity'])?></h6>
<p class="text-right">
<a class="btn btn-danger btn-sm " data-toggle="collapse" href="#collapseExample<?php echo ($row['did'])?>" aria-expanded="false" aria-controls="collapseExample<?php echo ($row['did'])?>">
Know More..
</a>
</p>
<div class="collapse" id="collapseExample<?php echo ($row['did'])?>">
<div class="card card-block">
<h5><span class="badge badge-warning">Contact Info</span></h5>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['demail'])?></h6>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['dmobile'])?></h6>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['daddress'])?></h6>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['dcity'])?></h6>
<h6 class="card-subtitle mb-2 text-muted"><?php echo ($row['dwebsite'])?></h6>
<!--ACCORDION START-->
<div id="accordion<?php echo ($row['did'])?>" role="tablist" aria-multiselectable="true">
<div class="card">
<div class="card-header" role="tab" id="headingOne<?php echo ($row['did'])?>">
<h5 class="mb-0 btn-sm">
<a data-toggle="collapse" data-parent="#accordion<?php echo ($row['did'])?>" href="#collapseOne<?php echo ($row['did'])?>" aria-expanded="true" aria-controls="collapseOne<?php echo ($row['did'])?>">
Image Description
</a>
</h5>
</div>
<div id="collapseOne<?php echo ($row['did'])?>" class="collapse show" role="tabpanel" aria-labelledby="headingOne<?php echo ($row['did'])?>">
<div class="card-block">
<?php echo $row['dimagedescription'] ?>
</div>
</div>
</div>
<div class="card">
<div class="card-header" role="tab" id="headingTwo<?php echo ($row['did'])?>">
<h5 class="mb-0 btn-sm">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion<?php echo ($row['did'])?>" href="#collapseTwo<?php echo ($row['did'])?>" aria-expanded="false" aria-controls="collapseTwo<?php echo ($row['did'])?>">
Software Used
</a>
</h5>
</div>
<div id="collapseTwo<?php echo ($row['did'])?>" class="collapse" role="tabpanel" aria-labelledby="headingTwo<?php echo ($row['did'])?>">
<div class="card-block">
<p class="card-text"><?php echo $row['dsoftwareused'] ?></p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" role="tab" id="headingThree<?php echo ($row['did'])?>">
<h5 class="mb-0 btn-sm">
<a class="collapsed" data-toggle="collapse" data-parent="#accordion<?php echo ($row['did'])?>" href="#collapseThree<?php echo ($row['did'])?>" aria-expanded="false" aria-controls="collapseThree<?php echo ($row['did'])?>">
My Brand Recommendation
</a>
</h5>
</div>
<div id="collapseThree<?php echo ($row['did'])?>" class="collapse" role="tabpanel" aria-labelledby="headingThree<?php echo ($row['did'])?>">
<div class="card-block">
<div class="card">
<ul class="list-group list-group-flush">
<li class="list-group-item"><?php echo $row['dbrandname'] ?></li>
<li class="list-group-item"><?php echo $row['dbrandsegment'] ?></li>
<li class="list-group-item"><?php echo $row['dbrandwebsite'] ?></li>
<li class="list-group-item"><?php echo $row['dbrandemail'] ?></li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!--ACCORDION END-->
</div>
</div>
</div>
<div class="card-footer">
<small class="text-muted">Design ID:- <?php echo stripcslashes($row['did']) ?> Submitted on :-<?php echo stripcslashes($row['dsubmissiondate']) ?></small>
<br>
</div>
</div>
</div>
<?php } ?>
</div>
<?php } else { ?>
<h3>No results found for the desired Search.</h3>
<?php } ?>
<!-- jQuery first, then Tether, then Bootstrap JS. -->
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js" integrity="sha384-vBWWzlZJ8ea9aCX4pEW3rVHjgjt7zpkNpZk+02D9phzyeVkE+jo0ieGizqPLForn" crossorigin="anonymous"></script>
<div>
<?php //for page numbers display at bottom of page
//Now select all from table for pagination
$sql = "SELECT * FROM ".$SETTINGS["data_table"]." WHERE did>0".$search_string.$search_dlocation." order by did desc";
$sql_result = mysql_query ($sql, $connection ) or die ('request "Could not execute SQL query" '.$sql);
// Count the total records
$total_records = mysql_num_rows($sql_result);
//Using ceil function to divide the total records on per page
$total_pages = ceil($total_records / $per_page);
//Going to first page
echo "<center><a href='displaydesign.php?page=1'>".'First Page'."</a> ";
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='displaydesign.php?page=".$i."'>".$i."</a> ";
};
// Going to last page
echo "<a href='displaydesign.php?page=$total_pages'>".'Last Page'."</a></center> ";
?>
</div>
</body>
I've been looking over your code, and I also setup an SQL-Fiddle (see below) to play around. I was initially thinking that maybe the MySQL query you use doesn't filter right on specific values or doesn't paginate right but filters right. Anyway there are also comments in the fiddle that explain some ideas and assumptions I made.
For what it's worth, pagination and complex SQL queries are non-trivial. They can also be expensive, and while I don't know your current code platform/setup/environment, I would suggest to push logic and things like pagination to the front end or JavaScript wherever possible. PHP works, too, but I'm mostly trying to point out that in my experience complexity for SQL queries often increases more quickly than code because it's a different type of frameset, namely relational versus procedural.
Your code also contains view and business logic together as well as SQL, so to be open with you I might not find the issue or there may be more than one. But I did notice some things looking at your code.
(1) The paginated results for your contacts list query were NOT exclusive by page number - meaning in some cases a row from a previous result would be included in the results.
(2) There is weird behavior if there are every any empty values for your WHERE conditions values -- specifically, $dname, $dcity, $dlocation. I didn't manage to reproduce your exact issue from JUST the SQL in the SQL fiddle, but I'm wondering if you'll see the same issues with some cleanup to the list query.
Fix Suggestions:
Modify SQL query to use rank and an inner-query to exclusive-paginate results and eliminate empty-match issues. In my suggested query below and in the fiddle, I've adjusted the WHERE condition from a AND (b or c) AND d to a AND ( (b or c) or d ) -- while this looks weird, it says "make sure we're matching on a non-empty location (assumed primary selector), or that we have a name or city to filter by". At least one variable must match true for the LIKE condition checks or it won't return a result row for it, whereas the other way required all three matches for a row (which is fine if those values will always be non-empty).
SET #name = "";
SET #city = "";
SET #location = "WA";
SET #per_page = 1;
-- Setting this arbitrarily - looking at different pages
-- mostly verifying yeah, the fetch/ pagination part works.
SET #page = 3;
SET #rownum = 0;
-- Basic Fetch Query used for getting list-for-page
SELECT
results.id, results.name,
results.location, results.city,
results.rank
FROM (
SELECT
c.id AS id
,c.name AS name
,c.location AS location
,c.city AS city
,#rownum := #rownum + 1 AS rank
FROM contacts AS c
-- ,(SELECT #rownum := 0) r
WHERE c.id > 0
AND ( (c.name LIKE #name OR c.city LIKE #city)
OR c.location LIKE #location )
ORDER BY c.id ASC
) AS results
WHERE rank BETWEEN ( (#page-1) * #per_page + 1) AND ( (#page) * #per_page )
Clarification
There are 2 new things going on in this bigger query. One, there is something called an "inner query" being used to pre-select a set of rows. Second, I'm assigning a rank value to use in my final results query to organize the table rows into "paged" results. This is a workaround to trying to use
WHERE ...
LIMIT ((#page-1)*#per_page), #per_page
or even
WHERE ...
LIMIT ((#page-1)*#per_page) OFFSET #per_page
But (see my CREDITS section), apparently one CANNOT use #vars in SQL. You could also work around this in your code by using PHP string templating or something, like you're already doing to inject variables into strings.
SQL Fiddle
Here's that SQL Fiddle to see what assumptions I made and what I was doing:
http://sqlfiddle.com/#!9/d516e/26
Credits
Apparently, one cannot use user variables like #name in the LIMIT-clause, which I did not know before. I found another Stack post to help me with that problem:
Using variable in a LIMIT clause in MySQL

How to limit the number of 'Recent Blogs' created in CakePHP?

I'm trying to create a blog, and in every single blog it shows the recent blogs that has been created on the bottom of the page. Is there a way i can limit this number to 4 recent blogs? Because currently all the blogs that has been created show's up on the "Recent Blogs" area when i generate it.
<div class="container" id="newsextra">
<h4>MORE NEWS</h4>
<div class="row">
<?php
if(!empty($error)){
echo $error;
}
if (!empty($blogsinfos)) {
foreach ($blogsinfos as $blogs): ?>
<div class="col-md-3">
<a href="/news-single/<?= h($blogs->id)?>">
<img src="<?= h($blogs->mainimg)?>" class="img-responsive">
<h5><?= h($blogs->title)?></h5>
<h6><?= h($blogs->created)?></h6>
</a>
</div>
<?php
endforeach;
}
?>
</div>
</div>
From the controller you should limit the number of posts generated. Thanks #Rik.esh for the answer.
$this->loadModel('Blogs');
$opts1['conditions'] = array('Blogs.status' => 1);
$opts1['limit'] = 4;
$opts1['order'] = array('Blogs.created' => 'desc');
$blogsinfos = $this->Blogs->find('all',$opts1);
$this->set('blogsinfos', $blogsinfos);
$this->set('_serialize', ['blogsinfos']);
foreach ($blogsinfos as $blogs) {
$proid = $blogs['id'];
}
try this
$opts1['order'] = 'Blogs.created desc';

Tile Thumbnails in a Grid

I want to tile thumbnails into 3 columns using bootstrap's grid classes like this (this entry only has 3 images):
The 4th image would go to the next row <div class="row"></div> within a <div class="col-sm-4"></div>, 5th and 6th images in the same row but separate <div class="col-sm-4"></div>. Then the 7th image goes to the 3rd row etc...
The details of the images including urls are taken from DB using php.
<div class="panel-body">
<?php foreach($screenshots as $key=>$screenshot): ?>
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?=$screenshot["ss_name"]?></h3>
</div>
<div class="panel-body">
<img class="img-rounded" style="display: block; text-align:center;" src="<?=UPLOADS_FOLDER.$screenshot['ss_url']?>" alt="<?=$screenshot['ss_name']?>">
<p><?=$screenshot["ss_description"]?></p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
I've managed to figure out the algorithim:
<?php
$total_entries = count($screenshots);
$total_cols = 3;
$total_rows = ceil($total_entries / $total_cols);
for($col = 0; $col < $total_cols; ++$col):
?>
<div class="row" style="margin: 1% 0.5%;">
<?php for($row = 0; $row < $total_rows; ++$row): ?>
<div class="col-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Panel Title</h3>
</div>
<div class="panel-body">
row: <?=$row?> | col: <?=$col?>
</div>
</div>
</div>
<?php endfor; ?>
</div>
<?php endfor; ?>
But I'm stuck trying to figure out how to find of the index of the screenshot to show.
You have row and column mixed up in the output above.
Once that is fixed, if you need an integer index you should be able to calculate it from the row and column values. For a zero based array of images, something like (row*3)+column
That said, in Bootstrap, you should not need to create the individual rows in the way you have. If you put all the col-sm-3 divs one after the other, without breaking out new rows, this will sort itself out anyway.
Doing it this way, you can use col-Xxx to specify different numbers of columns for different screen widths without changing your code.
The trick is to send every new data in a single column define by <div class="column-sm-4"> and in order to have three items in a row, calling <div class="row"> after every three items. Which can be done by using a counter initialized at 0 and then incrementing its value by 1 every time and inserting new row when dividing it by 3 results an integer:
$count = 0;
if (is_int($count/3)){
echo '<div class="row">';
}
We need to insert a div before first element so we check if its the starting:
if ($count==0 OR is_int($count/3)){
echo '<div class="row">';
}
Then in order to close the div we need to check again if the division results an integer:
if(is_int($count/3)){
echo '</div>' ;
}
We also need to close the div after the last element so we check whether the element is last one or not by:
if($count==$total_entries OR is_int($count/3)){
echo '</div>' ;
}
The full code is:
<?php
$count = 0;
$total_entries = count($screenshots);
foreach($screenshots as $key=>$screenshot):
if ($count==0 OR is_int($count/3)){
echo '<div class="row">';
}
?>
<div class="column-sm-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title"><?=$screenshot["ss_name"]?></h3>
</div>
<div class="panel-body">
<img class="img-rounded" style="display: block; text-
align:center;" src="<?=UPLOADS_FOLDER.$screenshot['ss_url']?>"
alt="<?=$screenshot['ss_name']?>">
<p><?=$screenshot["ss_description"]?></p>
</div>
</div>
</div>
<?php
$count++;
if($count==$total_entries OR is_int($count/3)){
echo '</div>' ;
}
endforeach;
?>

Display multiple images from database to bootstrap carousel

I have a lot of images in a DB and I want to display it in a bootstrap carousel using php.
[Problem]
I am rookie with php so I hit the wall. Let me explain with code.
<div class="carousel-inner">
<div class="item active">
<div class="row">
<div class="col-md-3"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></div>
<div class="col-md-3"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></div>
<div class="col-md-3"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></div>
<div class="col-md-3"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></div>
</div><!--.row-->
</div><!--.item-->
<?php
$pdo = connect();
// display the list of all members in table view
$sql = "SELECT * FROM filmovi";
$query = $pdo->prepare($sql);
$query->execute();
$list = $query->fetchAll();
?>
<div class="item">
<div class="row">
<?php foreach($list as $rs) { ?>
<div class="col-md-3"><img src="assets/img/movies/<?php echo $rs['slika'] ?>" alt="Image" style="max-width:100%;"></div>
<?php } ?>
</div><!--.row-->
</div><!--.item-->
</div>
As you can see, carousel shows 4 images at once and another 4 and so on. In a foreach loop as it is now I get all my images at once and item active is empty.
I need to get 4 by 4 images from the DB to carousel but don't know which way to go.
You need to specify a counter that will check after each 4 iterations, to create a new <div class="item">...</div> element.
<?php
$counter = 0; //Set the counter to zero
foreach ($list as $single_list){
if($counter % 4 == 0) { // On every fourth iteration create a new item and row DIV
echo '<div class="item"><div class="row">';
}
... your code to output the images ...
if($counter % 4 == 0) {
echo '</div></div>'; // Close the row and item DIV
}
$counter++;
}
If you have problems implementing the code, or you don't understand what I've done here, don't hesitate to ask.

Data not being displayed in tabs

I am displaying data from database which is linked to CMS. The problem I get is data from only one of my tabs is being displayed. Suppose I have two tabs, Tab 1, Tab 2. Instead of Tab 1 being active, Tab 2 is active and data is displayed of Tab 2. But, when I click on Tab 1, no data with respect to Tab 1 is displayed. The same data is present i.e Tab 2 data.
I am using mapping to get the ids of respective Tab.
<ul class="tabs" data-tab>
<?php
if(isset($X['list_by_parent_id'][0]) && !empty($X['list_by_parent_id'][0]))
{
$top_category_index=1;
foreach ($X['list_by_parent_id'][0] as $category_id)
{
?>
<li class="tab-title <?php if($top_category_index==1){ echo "active"; }?>"><?php echo $SITE['tmp']['product_categories'][$category_id] ?></li>
<?php
}
}
?>
</ul>
X is a global variable which is an array and stores everything.
This is the code that does mapping and displays the content.
<div class="category-content">
<div class="menu-cat-content tabs-content">
<?php if(isset($SITE['category_list_by_parent_id'][0]) && !empty($SITE['category_list_by_parent_id'][0]))
{
$top_category_index_mapped=1;
foreach ($SITE['category_list_by_parent_id'][0] as $category_id)
{ ?>
<div id="category-<?php echo $top_category_index_mapped; ?>" class="content <?php if($top_category_index_mapped++==1) { ?>active<?php } ?>">
//code for content
</div>
Rendered HTML:
<div class="category-content">
<div class="menu-cat-content tabs-content">
<div id="category-1" class="content active">
<!--sub category 1-->
</div><!--sub-category-clearfix2-->
<!--sub category 2 ends-->
</div> <!--category-div, index_mapped -->
<div id="category-2" class="content active">
<!--sub category 1-->
</div><!--sub-category-clearfix2-->
<!--sub category 2 ends-->
</div> <!--category-div, index_mapped -->
<div id="category-3" class="content active">
EDIT: I saw that top_category_index_mapped was set to 1 in category-*top_category_index_mapped. I replaced it and rendered html now looks like this.
This line:
$top_category_index=1;
sets the $top_category_index to 1 for the first tab. This line:
<li class="tab-title <?php if($top_category_index==1){ echo "active"; }?>
is equal to this the firs two times:
<li class="tab-title active">
because of the properties of the ++ operator. Read more here.
For example:
$a = 5;
echo "Should be 5: " . $a++ . "<br />\n";
echo "Should be 6: " . $a . "<br />\n";
Since you've only tested with two tabs it seems, that's why you are getting those results. It might also be helpful to include the rendered html.

Categories