I've created a navigation menu by PHP.
1) I need help how can i change link class for current page. I mean for example when HOME PAGE is open link should be like class="bla bla CURRENT"
2) Is there any suggest to better way for the LINK to that buttons.
HERE IS THE CODES
<?php
require_once('../config.php');
$sql= "SELECT * FROM veri_kategori";
foreach ($dbh->query($sql) as $row)
{
echo "<li class=\"dropdown\">".$row["tr"]."</li>";
}
?>
Try this solution:
<?
require_once('../config.php');
// Get the current page.
$pag = $_GET['pag'];
if (isset($pag)) {
if ($page == 'about') {
// Redirect or include your page.
} else if ($page == 'contact') {
// Redirect or include your page.
}
} else {
// Redirect or include your home page.
}
$sql = "SELECT * FROM veri_kategori";
foreach ($dbh->query($sql) as $row) {
// Set default class.
$class = "dropdown-toggle";
// If home page, set another class.
if (!isset($pag)) {
$class = "bla bla CURRENT";
}
echo "<li class=\"dropdown\">{$row["tr"]}</li>";
}
?>
Related
I'm working on my script site I have the url setup like this with PHP.
movies.php?pages=action
But every time a member goes to the url it pulls the page name from movies.php how can I fix this issue I have pasted my code down below.
<?php
// StreamPlex Page System - Play Page
DEFINE("IN_STREAMPLEX", 1);
$pageName = "All Movies";
require_once('inc/config.php');
require_once('inc/header.php');
$action = $_GET['action'];
$pages = $_GET['pages'];
if(isset($pages)) {
require_once("{$pages}.php");
} else {
?>
Then at the bottom of the page I have finished off with this code here
<?php include 'inc/footer.php'; ?>
<?php } ?>
Can somebody please help me in telling me what I'm doing wrong.
I have fix the issue i had change around the code at the top of the page from
<?php
DEFINE("IN_STREAMPLEX", 1);
$pageName = "All Movies";
require_once('inc/config.php');
require_once('inc/header.php');
$action = $_GET['action'];
$pages = $_GET['pages'];
if(isset($pages)) {
require_once("{$pages}.php");
} else {
?>
To this
<?php
// StreamPlex Page System - Play Page
DEFINE("IN_STREAMPLEX", 1);
$action = $_GET['action'];
$pages = $_GET['pages'];
if(isset($pages)) {
require_once("{$pages}.php");
} else {
$pageName = "All Movies";
require_once('inc/config.php');
require_once('inc/header.php');
?>
Now it works in loads with no problems.
how do i tell this php code that, when there's not a ?page=randompage in the url, it will trow the active to index.php automatically?
<?php
$query = "SELECT pagename, pagetitle FROM pages LIMIT 8";
$result = $mysqli->query($query);
echo "<ul>";
while ($row = $result->fetch_array(MYSQLI_ASSOC)){
echo "<li><a href=\"?page=".$row["pagename"]."\"";
if ($_GET['page'] == $row['pagename']) {
echo " class=\"active\""; } echo "> ".$row["pagetitle"]." </a></li>";
}
echo "</ul>";
?>
It's beacuse whenever my url looks like this http://localhost/greencph/ it shows a php error, because it does not know which site it is on, it works perfect as long as the url looks like this: http://localhost/greencph/?page=index.php a detailed explanation on how to fix this problem would be appreciated!
Please remember i'm a idiot, explain to me so i understand it. xD
The error is coming because, every time the value of $_GET is not getting set.
So, to deal with it,
get the value of $_GET['page'] in a variable.
So that, if we do not get $_GET, we will assign it a default value, that is index page.
$page = ! empty($_GET['page']) ? $_GET['page'] : 'index'; // set default value.
And change this line:
if ($page == $row['pagename']) {
So, the final modified code should be:
<?php
$query = "SELECT pagename, pagetitle FROM pages LIMIT 8";
$result = $mysqli->query($query);
$page = ! empty($_GET['page']) ? $_GET['page'] : 'index';
echo '<ul>';
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
$class = '';
if ($page == $row['pagename']) {
$class = 'active';
}
echo '<li>' . $row["pagetitle"].' </li>';
}
echo "</ul>";
?>
Use the $_GET array:
<?php
if(isset($_GET['page'])) {
// Your code
...
}
?>
Problem is in this line
if ($_GET['page'] == $row['pagename']) {
You're not checking whether the index 'page' even exists. So, when you try to load the page without any GET parameters $_GET['page'] won't be even set and you'll get an error for accessing unset element.
To fix this simply check
if(isset($_GET['page']) {
...your code...
}
I have a situation whereby i want two of my pages to look different form the rest but they are not front pages. If they were it would be easy as the code below would do the trick.
$menu = & JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
esle(do something else)
}
?>
In short i want a similar approach but this time, to get the menu by ID/URL. Any ideas?
I got the answer to this...all you need to check is the menu ID then put the code below.
<?php
//This is the code for the page with menu ID 6
$menuID = JSite::getMenu()->getActive()->id ;
if ($menuID == '6')
{
echo '';
}
elseif ($menuID == '2') //This is the HTML for page with menu ID 2
{
echo '';
}
elseif ($menuID == '4') //THis is the html for page with menu id 4
{
echo '';
}
else //This is the HTML code for the rest of the pages
{
echo '';
}
?>
Page ItemId can be obtained using $itemid = JRequest::getInt( 'Itemid' );
I'm using Mick Sears' php breadcrumb script - found here:
http://www.roscripts.com/PHP_breadcrumbs-118.html
I've used this script several times with no problems. But with this one site I'm having the weirdest problem... Home page - fine. Level 1 page - fine. But every time I move to a level2 page, the correct level1 crumb is replaced by "Help". The link on the crumb is the correct one for the help page. This happens even if I clear all browser caches and don't go to the Help section of the site at all.
The site is http://www.fastexas.org. The script is there, but I gave the breadcrumb div display:none; until I can figure this out.
This script seems to have been around awhile and I'm wondering if anyone else has seen this problem.
The Breadcrumb Script:
<?php
class Breadcrumb{
var $output;
var $crumbs = array();
var $location;
function Breadcrumb(){
if ($_SESSION['breadcrumb'] != null){
$this->crumbs = $_SESSION['breadcrumb'];} }
function add($label, $url, $level){
$crumb = array();
$crumb['label'] = $label;
$crumb['url'] = $url;
if ($crumb['label'] != null && $crumb['url'] != null && isset($level)){
while(count($this->crumbs) > $level){
array_pop($this->crumbs); }
if (!isset($this->crumbs[0]) && $level > 0){
$this->crumbs[0]['url'] = "/index.php";
$this->crumbs[0]['label'] = "Home";}
$this->crumbs[$level] = $crumb;}
$_SESSION['breadcrumb'] = $this->crumbs;
$this->crumbs[$level]['url'] = null;}
function output(){
echo "<ul>";
foreach ($this->crumbs as $crumb){
if ($crumb['url'] != null){
echo "<li> <a href='".$crumb['url']."' title='".$crumb['label']."'>".$crumb['label']."</a></li> ";} else {
echo "<li class='last'>".$crumb['label']."</li> ";}}
echo "</ul>";}}
?>
Each page begins with something like:
<?php session_start();
$level= '1';
$label= 'Honors Circle';
$url= '/honors/'; include($_SERVER['DOCUMENT_ROOT']."/includes/Breadcrumb.php");
$trail = new Breadcrumb();
$trail->add($label, $url, $level); ?>
or
<?php
session_start();
$level= '2';
$label= 'Districts';
$url= '/honors/district.php';
include($_SERVER['DOCUMENT_ROOT']."/includes/Breadcrumb.php");
$trail = new Breadcrumb();
$trail->add($label, $url, $level);
?>
And to print the breadcrumb trail:
<div id="breadcrumb"><?php $trail->output(); ?></div>
I am working on a Wordpress Theme, I need to work on the navigation, I am having a little trouble creating it.
The navigation I am looking for looks like this: www.neu.edu/humanities.
I have gotten this far:
if (is_front_page()) {
wp_list_pages('title_li=&exclude=12&depth=1');
}
else {
// display the subpages of the current page while
// display all of the main pages and all of the
// and display the parent pages while on the subpages
}
<?php
if (is_front_page()) {
wp_list_pages('title_li=&exclude12&depth=1');
}
else {
$output = wp_list_pages('echo=0&depth=1&title_li=&exclude=12');
if (is_page()) {
$page = $post-ID;
if ($post->post_parent) {
$page = $post->post_parent;
}
$children = wp_list_pages('echo=0&child_of='.$page.'&title_li=&exclude=12');
if ($children) {
$output = wp_list_pages('echo=0&child_of='.$page.'&title_li=&exclude=12');
}
}
echo $output;
}
?>