2 Replies - 1148 Views - Last Post: 16 December 2012 - 03:23 AM Rate Topic: -----

#1 hwoarang69  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 171
  • Joined: 23-October 12

link not being set to active class

Posted 15 December 2012 - 11:27 PM

http://cssdeck.com/l...gination-styles

i was trying to put this pasination on my site. it works fine. all the page do change but only one problem.
if i am on les say page 1. than link 1 background should be darker, so it look like i am on page 1. i think the problem is the link are not being set to active class. for ex on cssdeck.com they have
<span class="page dark active">4</span>





///////////////////////////////
	/****** pagination **********/
	///////////////////////////////
	if($pages >= 1 && $page <= $pages)
	{
		echo"<div id='container'>";
			echo"<div class='pagination dark'>";
				echo'<a href="?page=1" class="page dark">first</a>';
				for($x=2; $x< $pages; $x++) //botom pages link
				{
				  echo'<a href="?page='.$x.'" class="page dark">'. $x .'</a> '; 
				}
				echo'<a href="?page='. $x .'" class="page dark">last</a>';
			echo"</div>";
		echo"</div>";
	}

This post has been edited by hwoarang69: 15 December 2012 - 11:32 PM


Is This A Good Question/Topic? 0
  • +

Replies To: link not being set to active class

#2 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3352
  • View blog
  • Posts: 11,345
  • Joined: 12-December 12

Re: link not being set to active class

Posted 16 December 2012 - 03:17 AM

Something like the following, assuming $page refers to the current page:

///////////////////////////////
    /****** pagination **********/
    ///////////////////////////////
    if($pages >= 1 && $page <= $pages)
    {
        echo"<div id='container'>";
            echo"<div class='pagination dark'>";
                echo'<a href="?page=1" class="page dark">first</a>';
                for($x=1; $x <= $pages; $x++) //botom pages link
                {
                    $pageno = ($x == 1) ? "first" : ($x == $pages) ? "last" : $x;
                    // assuming $page is the current page..
                    $active = ($x == $page) ? " active" : "";
                    echo "<a href='?page={$x}' class='page dark{$active}'>{$x}</a>"; 
                }
            echo"</div>";
        echo"</div>";
    }


I cannot edit my previous post, so the line should be:

echo "<a href='?page={$x}' class='page dark{$active}'>{$pageno}</a>";

Then you need to style the class .active, or whatever name you care to use.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is offline

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3352
  • View blog
  • Posts: 11,345
  • Joined: 12-December 12

Re: link not being set to active class

Posted 16 December 2012 - 03:23 AM

But, of course, you need a page reference in there:

echo "<a href='somepage.php?page={$x}' class='page dark{$active}'>{$pageno}</a>";

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1