Click here to Skip to main content
15,906,567 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
<?php 
function getPagination($categories, $page, $totalPages){
		
		$pagination = "";

		if($page > 1){
			
			if($page == 2){
				
				$previousLink = $categories['CATEGORY_FILE_NAME'].".html";
			}else{
				
				$previousLink = $categories['CATEGORY_FILE_NAME']."-".($page-1).".html";
			}
			
			$pagination .= "<a href=\"https://india.com/".strtolower($previousLink)."\">Previous";
			
			
		}
		
		if($totalPages <= 5 OR $page < 3){
			
			if($totalPages > 5){ $totalPages  = 5;}
			
			for($j = 1; $j<= $totalPages; $j++){
				
				if($j==1){
					
					$pagination .= "<a href=\"https://india.com/".$categories['CATEGORY_FILE_NAME'].".html\">$j";
					
				}else{
					
					$pagination .= "<a href=\"https://india.com/".$categories['CATEGORY_FILE_NAME']."-".$j.".html\">$j";
					
				}
			}	
		}else if(($page+2) > $totalPages){
			
			for($j=($totalPages-4); $j<= $totalPages; $j++){
				
				if($j==1){
					
					$pagination .= "<a href=\"https://india.com/".$categories['CATEGORY_FILE_NAME'].".html\">$j";
					
				}else{
					
					$pagination .= "<a href=\"https://india.com/".$categories['CATEGORY_FILE_NAME']."-".$j.".html\">$j";
					
				}
				
			}	
		}else{
						for($j=($page-2); $j <= ($page+2); $j++){
				
				if($j==1){
					
					$pagination .= "<a href=\"https://india.com/".$categories['CATEGORY_FILE_NAME'].".html\">$j";
					
				}else{
					
					$pagination .= "<a href=\"https://india.com/".$categories['CATEGORY_FILE_NAME']."-".$j.".html\">$j";
					
				}	
			}
		}
		
		if($page < $totalPages){
			$pagination .= "<div class=\"col-xs-6\" style=\"padding:5px;\"><div style=\"float:right\"><a href=\"https://india.com/".$categories['CATEGORY_FILE_NAME']."-".($page+1).".html\">Next";	
		}
		return $pagination;
	}
?>


What I have tried:

please help me i try to add class="active" (i.e if i am in first page - one number will be bold in the pagination..

< 1 2 3 4 5 > (i.e 1 number will be bold) if i am in second page automatically second number will be bold only othernumbers will be normal
Posted
Updated 30-Nov-18 0:35am
v2

1 solution

We dont have much room here to work with the code you supplied.

Do you want a html/css solution ? or hardcoded php solution ?

hardcoded php solution (not recommended) would be something like this:

PHP
function Page_number($page, $max_pages)
{
	for ($i = 1, $i < ($max_pages + 1), $i++)
	{
		echo "<a href=\"whateverfile.html\">" . ($page == $i) ? "[boldtag]" . $i . "[/boldtag]" : $i . "</a> ";
	}
}


but then again, im not exactly sure what you exactly want/need.

[boldtag] = < b > for some reason in the code window this is being stripped.

But best tip i can give you is, to rewrite the entire code
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900