thara Posted November 1, 2012 Share Posted November 1, 2012 this code I used to display paginating links... problem is I need to add some style to the links when its active.. I can style it through some CSS rules.. but at first need to add a class to link tag.. Eg: <a class="selected" ></a> // Make the links to other pages, if necessary. if ($pages > 1) { echo '<div class="pagination">'; echo '<p>'; // Determine what page the script is on: $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous link: if ($current_page != 1) { echo '<a href="searching.php?s=' . ($start - $display) . '&p=' . $pages . '"><</a>'; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="searching.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button: if ($current_page != $pages) { echo '<a href="searching.php?s=' . ($start + $display) . '&p=' . $pages . '">></a>'; } echo '</p>'; // Close the paragraph. echo '</div>'; } // End of links section. can anybody have any idea how to do this? thank you.. Quote Link to comment https://forums.phpfreaks.com/topic/270147-adding-a-class-to-tag/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2012 Share Posted November 1, 2012 If you mean the currently selected page, it's just the page number, not a link. You would output the page number inside of a <span class='selected'>$i</span> Quote Link to comment https://forums.phpfreaks.com/topic/270147-adding-a-class-to-tag/#findComment-1389201 Share on other sites More sharing options...
thara Posted November 1, 2012 Author Share Posted November 1, 2012 no.. I only need to add a class to <a> tag when page is active.. assume page 1 is active.. then I need to add a class to that link.. resion is I need to style the link when it is activating.. Quote Link to comment https://forums.phpfreaks.com/topic/270147-adding-a-class-to-tag/#findComment-1389202 Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2012 Share Posted November 1, 2012 Where in your code do you see a link being output for the current/active page? There are links for the previous page (if any), the pages other than the current/active page, and the next page (if any.) Quote Link to comment https://forums.phpfreaks.com/topic/270147-adding-a-class-to-tag/#findComment-1389204 Share on other sites More sharing options...
thara Posted November 1, 2012 Author Share Posted November 1, 2012 I have styled it.. but problem is I cant style when a link is activating... eg: if page 1 is active then I need to add some styles for that link. thats why I need to add another class to the <a>.. Quote Link to comment https://forums.phpfreaks.com/topic/270147-adding-a-class-to-tag/#findComment-1389205 Share on other sites More sharing options...
PFMaBiSmAd Posted November 1, 2012 Share Posted November 1, 2012 The following is your code for the current/active page - echo $i . ' '; I's not a link. It's text. Someone already showed you how to put a span around it to style it with a css class. Quote Link to comment https://forums.phpfreaks.com/topic/270147-adding-a-class-to-tag/#findComment-1389207 Share on other sites More sharing options...
thara Posted November 1, 2012 Author Share Posted November 1, 2012 thanks PFMaBiSmAd its working now. Quote Link to comment https://forums.phpfreaks.com/topic/270147-adding-a-class-to-tag/#findComment-1389208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.