PHP - Php Pagination - Hightlight Current Page
I've looked at loads of other scripts that highlight the page but none of them work on mine . Here's part of my code:
$i =1; for ($x=0;$x<$foundnum;$x=$x+$e) { echo " <a href='search.php?search=$search&s=$x'>$i</a> "; $i++; Similar Tutorialsis this possibe with php? Hi, This may be something for JavaScript but I would like to know if and how it's possible to show who is currently active/viewing the page. Users are logged into the system with their own account. The purpose of this is for a CRM where more than one person may be editing the same record, so undesired overwrites might occur which is what I'd like to avoid with this "other user editing this record" notification. I am trying to create a script that alters the navigation div depending on the page the user is on. How do I get the current page using PHP? Why this code dont work :S <?php echo ' <ul> <li'; if ($_SERVER['PHP_SELF'] == "kategorije.php") { echo ' id="current"'; } echo '><a href="kategorije.php"><span>Kategorije</span></a></li> </ul>'; ?> Checking if PHP_SELF is "kategorije.php" do not work, why, and what is solution ? Hi guys, I'll try to explain this. I'm doing a quoting system for a building contractor and I have a dynamic purchase order created for every quote that's confirmed and it spits out all the materials they will need for each supplier. The layout of the page is exactly what I need emailed to the supplier so they can ship out the materials listed, it's your basic purchase order. I'm going to put a button on the page that sends the email to the supplier but I need to attach the purchase order displayed on the page. Preferably in PDF but it just needs to be an attached file. I know I can have the user use PRINT.... to save it as PDF and then use Outlook to email it but I'd like to automate it. Thanks. Hi all, I want to get the current page name as displayed in the URL, not neccesarily the name of the PHP script that is running. E.g. I have a PHP file 'home.php' that contains iframes that contain other PHP files such as 'frame1.php'. What I want is a script that can be run from frame1.php but that will return 'home.php' as the current page (as displayed in the URL in the browser). How do I do this? Thanks! I have an html table that is being populated with links from a specific directory.. I would like the user to be able to click the link and if its a file they will download the file. If its a directory, I woudl like to reload the current page but this time show the contents of the directory. My main issue is that I have a session variable called 'workingdirectory' that I need to update before I reload the page. I have tried setting it and then calling Location('page.php') but I get the 'cannot change header information' error. I realized I was getting this because I had begun to call HTML code before the PHP was finished. Is there a way to just simply update the session variable, and then make the page reload when the user clicks on a link? I have a few PHP files. Currently, if the URL contains page=var, index includes var.php, otherwise it includes home.php. Apparently, this method makes the site easy to hack through Remote File Inclusion. Also, using PHP5 breaks this method entirely, as no matter what you set page to in the URL, it includes home.php. What's the best way to do this without using the URL? Give example code if possible. I've used PHP for a while but haven't really gotten past the beginner level. I'd really appreciate any help. Thanks. Is there a function to check the name of the current page? Such as login.php or something like that? If not, does anyone have a custom function already created? I'm feeling a little overwhelmed/burned-out/confused... I have a page "article_index.php" that contains a summary of each article plus a link to it, e.g. Code: [Select] <a href="<?php echo WEB_ROOT; ?>articles/postage-meters-save-you-money"> When you click on a link, it goes to "article.php" and uses a mod_rewrite to transform the "pretty URL" to regular URL that "article.php" can use to query the correct article from my database. ----- Here is what I need help with... When a user is on a given article page, I want to sto - ReturnToPath - ArticleID in the SESSION. I am drawing a blank on how to get the "ArticleID" when a user is on a give page?! Hope you guys follow me?! Debbie Hi Everyone, I have this small bit of PHP that when you are on a certain page it will add a class called selected Code: [Select] <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> <ul id="subnav"> <li><a href="gallery.php?category=Wedding" id="wedding" <?php if ($currentPage == 'gallery.php?category=Wedding') {echo 'class="selected"';} ?>>Wedding Hair</a></li> <li><a href="gallery.php?category=Men" id="mens-styles" <?php if ($currentPage == 'gallery.php?category=Men') {echo 'class="selected"';} ?>>Mens Styles</a></li> <li><a href="gallery.php?category=Women" id="womens-styles" <?php if ($currentPage == 'gallery.php?category=Women') {echo 'class="selected"';} ?>>Women's Styles</a></li> <li><a href="gallery.php?category=Salon" id="salon" <?php if ($currentPage == 'gallery.php?category=Salon') {echo 'class="selected"';} ?>>Salon</a></li> </ul> This is not working I think it's because of the file extenstion 'gallery.php?category=Wedding' is there any way I can get this to work with these extensions Any help would be greatly appreciated Thanks Barry I'm doing a cURL post to a server and it returns "true No_Error Data was accepted 10356546 3770 false 0 " Form --> Method=Post --> submit.php (this is the page that's doing the cURL post and the server returns data that appears on this page). How do I take this and put it into a string? Hello, I'm having trouble figured out how to do this... Basically I want update.php to run after the user hits the 'update' button, and after update.php runs (which will take about 60 seconds) I want the index.php to reload. How can this be done? thanks! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <title>Server List</title> </head> <body> <?php $mlink = @mysql_connect("localhost","user","pass"); mysql_select_db("dbname", $mlink); $result = mysql_query("SELECT * FROM ServerList"); while($row = mysql_fetch_array($result)){ echo $row['HostName']. " - ". $row['UsedSlots']. " / ". $row['MaxSlots']; echo "<br />"; } ?> <br/> <br/> <form action="update.php" method="post"> <button type="submit">update</button> </form> </center> </body> </html> Hello, I got this basic code from a website and it is supposed to highlight the current page on the menu, which it does very well. The problem is that I cannot stylize the font, color or size of the type in the current page menu display. No matter what I do, it always stays as the default font. The other buttons on the menu can be stylized but not the current page. Is there a way to do this? Code: [Select] ## SNIPPET 1 - THE PHP ## // To be saved in the 'includes' directory as "nav_include.php" <?php $menu=file_get_contents("includes/menu.html"); // get the navigation list of pages $base=basename($_SERVER['PHP_SELF']); // get the current page $menu=preg_replace("|<li><a href=\"".$base."\">(.*)</a></li>|U", "<li id=\"current\">$1</li>", $menu); // add an id of 'active' to the link and id of class to the list item for the current page echo $menu; // echo the HTML list with the current page highlighted ?> ## SNIPPET 2 - THE HTML LIST ## To be saved as menu.html <ul id="navlist"> <li><a href="index.php">Home</a></li> <li><a href="products.php">Products</a></li> <li><a href="services.php">Services</a></li> <li><a href="about.php">About Us</a></li> <li><a href="contact.php">Contact Us</a></li> </ul> ## CSS ## for the *.css file #navlist { margin: 0; padding: 30px 0 20px 10px; float: right; width: 60%; } #navlist ul, #navlist li { margin: 0; padding: 0; display: inline; list-style-type: none; } #navlist a:link, #navlist a:visited { float: left; line-height: 14px; font-weight: bold; margin: 0 10px 4px; text-decoration: none; color: #4F4F4F; width: auto; } /* link and visited link styles - the visited state can be styled separately if you wish */ #navlist a:link#current, #navlist a:visited#current, #navlist a:hover { border-bottom: 4px solid #66733f; padding-bottom: 2px; background: transparent; color: #4F4F4F; } /* this line's the style for the current page link */ #navlist a:hover { border-bottom: 4px solid #4F4F4F; color: #4F4F4F; } /* hover state for all the links */ ## TO DISPLAY ON THE PAGE ## <?php include("includes/nav_include.php"); ?> So, here goes...
On my website, http://jamaica2go.com, I have destinations laid out in thumbnails on the main destination page. The page is using three columns. The page works fine as it is, however, I know that as I add more locations scrolling will become an issue. The author did a great job on this theme and he also gave an option to select maximum number of items to be shown but no paging occurs once you hit that max (weird, right?).
I have tried, I really have. Reading up on the WP codex, hunting down scripts and tutorials, all with a view to adding this simple feature. I know if someone figures this out it's going to be easy as cheese but the drawback for me is that I'm not a PHP programmer, just pretty decent at editing and changing the code.
Anyway, I'm posting the entire page code below (realised at end that I can attach, so did that instead). The important stuff happens in the "uxbarn_custom_port_load_portfolio_shortcode" function and onward. I noticed that although he starts a while loop to write the thumbnails to the page, he doesn't seem to end it. He also has a pagination template for the blog page which I'll add below but I couldn't make heads or tails of it. Hope someone can assist.
PORTFOLIO PAGE
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
The template below is used for blog and search and is called with:
<?php get_template_part( 'template-pagination' ); ?>
PAGINATION TEMPLATE
------------------------------------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------------------------------------
<?php $big = 999999999; global $wp_query; $total_pages = $wp_query->max_num_pages; if( is_search() ) { // Only for search page, there are 10 posts per page // And always round up the result $total_pages = ceil( $wp_query->found_posts / 10 ); } if ( $total_pages > 1 ) { echo '<div class="row no-margin-bottom"> <div id="blog-pagination" class="uxb-col large-12 columns pagination-centered"> '; $current_page = max( 1, get_query_var( 'paged' ) ); echo paginate_links( array( 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), 'format' => '&page=%#%', 'current' => $current_page, 'total' => $total_pages, 'prev_text' => '<i class="icon ion-ios7-arrow-left"></i>', 'next_text' => '<i class="icon ion-ios7-arrow-right"></i>', 'type' => 'list' )); echo '</div> </div>'; } ?> ------------------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------------------------------------------------ Attached Files custom-uxbarn-portfolio.php 33.24KB 2 downloads template-pagination.php 1022bytes 0 downloads Hi, I have pagination system with FIRST LETTER separated and everything is OK.
$page = (int)(!isset($_GET["page"]) ? 1 : $_GET["page"]); if ($page <= 0) $page = 1; $per_page = 5; $startpoint = ($page * $per_page) - $per_page; $statement = "restaurants ORDER BY `name`"; // make foo the current db '" . addslashes($_GET['id']) . "' $result = mysqli_query($mysqli,"SELECT name FROM restaurants WHERE cuisine_ID_obsolete=5 ORDER BY name LIMIT {$startpoint} , {$per_page}"); if (mysqli_num_rows($result) == 0) { echo "No records are found."; } else { $lastFoundLetter = ''; // displaying records. while ($row = mysqli_fetch_array($result)) { $firstLetter = substr($row['name'], 0, 1); if ($firstLetter != $lastFoundLetter) { if ($lastFoundLetter != '') { echo "</br>"; } echo strtoupper($firstLetter) . "<br/>"; $lastFoundLetter = $firstLetter; } echo $row['name'] . "<br/>"; } } echo pagination($statement,$per_page,$page); ?>Function for pagination: <?php function pagination($query,$per_page=10,$page=1,$url='?'){ global $mysqli; $query = "SELECT COUNT(*) as `num` FROM restaurants WHERE cuisine_id_OBSOLETE = '12'"; $row = mysqli_fetch_array(mysqli_query($mysqli,$query)); $total = $row['num']; $adjacents = "1"; $prevlabel = "<img src='files/prev.png'>"; $nextlabel = "<img src='files/next.png'>"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; // //last page minus 1 $pagination = ""; if($lastpage > 1){ $pagination .= "<ul class='pagination'>"; if ($page > 1) $pagination.= "<li><a href='{$url}page={$prev}'>{$prevlabel}</a></li>"; if ($lastpage < 7 + ($adjacents * 2)){ for ($counter = 1; $counter <= $lastpage; $counter++){ if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } } elseif($lastpage > 1 + ($adjacents * 2)){ if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){ if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } $pagination.= "<li class='dot'>...</li>"; $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>"; $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>"; } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<li><a href='{$url}page=1'>1</a></li>"; $pagination.= "<li><a href='{$url}page=2'>2</a></li>"; $pagination.= "<li class='dot'>...</li>"; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } $pagination.= "<li class='dot'>..</li>"; $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>"; $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>"; } else { $pagination.= "<li><a href='{$url}page=1'>1</a></li>"; $pagination.= "<li><a href='{$url}page=2'>2</a></li>"; $pagination.= "<li class='dot'>..</li>"; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<li><a class='current'>{$counter}</a></li>"; else $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>"; } } } if ($page < $counter - 1) $pagination.= "<li><a href='{$url}page={$next}'>{$nextlabel}</a></li>"; $pagination.= "</ul>"; } return $pagination; } ?>Problem is, since I have FIRST LETTER separated, with $per_page. How to exclude FIRST LETTER and "<br/>" from $per_page variable? Hi everyone, I have this script that identify's the current page in the navigation Code: [Select] <?php $currentPage = basename($_SERVER['SCRIPT_NAME']); ?> <ul id="nav"><!-- Open Nav --> <li><a href="index2.php" <?php if ($currentPage == 'index2.php') {echo 'class="selected"';} ?>>Home</a></li> <li><a href="salon-information.php" <?php if ($currentPage == 'salon-information.php') {echo 'class="selected"';} ?>>Salon Information</a></li> <li><a href="about-us.php" <?php if ($currentPage == 'about-us.php') {echo 'class="selected"';} ?>>About us</a></li> <li><a href="hair-care-advice.php" <?php if ($currentPage == 'hair-care-advice.php') {echo 'class="selected"';} ?>>Hair Care Advice</a></li> </ul><!-- Close Nav --> My problem is that hair-care-advice.php has a number of sub pages. How do I get it so the selected class remains selected for all the sub pages as well as the main page. Any help would be greatly appreciated Thank you Barry Hello- I have a social network that has a blogs and questions section. There are community pages for each one ( blogs/questions ) On each of those pages. the first ten blogs/questions are displayed. To the right of those are a list of clickable categories that sort the pages according to their category. I have pagination implemented after each ten. I am doing a mod_rewrite for pretty urls on my dev and have everything working correctly. The problem is, after hitting next the first time 'page=' is blank and just reloads the first (defaulted page) but after a second click it becomes 'page=10' as it should and then the third click 'page=20" as it should. So basically I am trying to get it to go to 'page=10" after one click, not two. Here is the code for the pagination: Code: [Select] <div id="all_page_turn"> <ul> <?php if($totalBlogs > 10 && $_GET['page'] >= 10) { ?> <li class="PreviousPageBlog round_10px"> <a href="/blogs/?cat=<?php if(isset($_GET['cat'])) { echo $_GET['cat'];} ?>&sort=<?php if(isset($_GET['sort'])) { echo $_GET['sort'];} ?>&page=<?php if(isset($_GET['page'])) { echo ($_GET['page'] - 10);} ?>">Previous Page</a> </li> <?php } ?> <?php if($totalBlogs > 10 && $_GET['page'] < ($totalBlogs-10)) { ?> <li class="NextPageBlog round_10px"> <a href="/blogs/?cat=<?php if(isset($_GET['cat'])) { echo $_GET['cat'];} ?>&sort=<?php if(isset($_GET['sort'])) { echo $_GET['sort'];} ?>&page=<?php if(isset($_GET['page'])) { echo ($_GET['page'] + 10);} ?>">Next Page</a> </li> <?php } ?> </ul> </div> </div>and here is the defaulted category link: Code: [Select] <div id="RightBlogs"> <div id="search_blogs_future" class="round_10px"> <form name="searchBlogs" action="/blogs" method="get"> <input type="text" name="BlogSearch" class="text" value="<?php if(empty($_GET['BlogSearch'])) { echo "Search Blogs"; }else{ echo $_GET['BlogSearch'];} ?>" onclick="clearify(this);" /> <input type="submit" name="subBlogSearch" value="Search" /> </form> </div> <div class='<?php if(empty($_GET['cat']) || $_GET['cat'] == "All") { echo "all_blog_cats_Highlighted"; }else{ echo "all_blog_cats_unHighlighted"; } ?> round_10px'> <a href='/blogs/?cat=All'> All </a> </div>Here is a screen shot of the page, as I'm on my dev so I can't provide a link. you can't see the "next" button, but it's there on the bottom, and then the categories are on the right. [attachment deleted by admin] Hi, Can any one help me wit the pagination in android mobile App Pls find the attached file for full code As per the below coe it displays only 40 posts but i have around 500 posts. I can increse function add_query_vars($public_query_vars) { $public_query_vars[] = $this->namespace.'_p'; return $public_query_vars; } $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'category__in' => $categories, ); if ($wp->query_vars[$this->namespace.'_p'] == 1){ $args['posts_per_page'] = 10; $args['offset'] = 0; }else{ $args['posts_per_page'] = 40; $args['offset'] = 10; } $posts = get_posts($args); I have tried but i am getting only 210 posts.only if i increse the post_per_page more than 70 in mobile android app it shows loding $args = array( 'post_type' => 'post', 'post_status' => 'publish', 'category__in' => $categories ); if ($wp->query_vars[$this->namespace.'_p'] == 1){ $args['posts_per_page'] = 70; $args['offset'] = 0; } if ($wp->query_vars[$this->namespace.'_p'] == 2){ $args['posts_per_page'] = 140; $args['offset'] = 70; } if ($wp->query_vars[$this->namespace.'_p'] == 3){ $args['posts_per_page'] = 210; $args['offset'] = 140; } $posts = get_posts($args); Attached Files wp-app-maker.php 49.23KB 1 downloads |