linkage through mapped php pages from menu - php

To try to map up all the pages, I've made a couple of maps called products and similar naming.
However when I go through a link with, for example, product/xxx.php and press the same link within the menu at that page I've entered, I get an adding of products/products/xxx.php, which break the link.
How do you avoid or correct these sort of linkages?
so for example I have my main menu inside a php file called menu.php which I include in the index.php by php include
a snip of the main menu php is
<div class="menuBar">
<ul id="menu">
<li>xxx
<div class="dropdown_unit">
<!-- Header -->
<div class="unitSizer">
<h4>xxx</h4>
</div> <!-- END Header -->
and it is placed within a div at the index.php
like this:
<div class="menuBar">
<?php include 'menu.php'; ?>
</div> <!-- END menuBarDental -->
this is just 1 part of the menu but it looks the same overall inside the menu.php
the problem here is that it seems by include this php file into the index.php and generating
the links inside the menu it keeps adding instances of the links.

Related

Is it possible to link to a header.php and footer.php from different folder sources?

I'm a beginner at PHP.
I have multiple webpages residing in different locations. So when I wish to link to header.php and footer.php from the webpages in different folders, is it possible to do so? As shown in the picture, I have to create three different folders, containing same files, header.php and footer.php, to be able to link from three different sources.
With Best regards!
Yes it is possible to use a single footer.php and single header.php files and load them anytime you need.
What I would suggest you can do is that you create an include folder, then inside the include folder create another folder called common where by you will place website that elements that are always the same throughout the website ie, footer and header.
then I would also place a functions file inside the includes where I will place my website functions. Included in this function file is a function that I will use anytime I want to use the header.php and footer.php files.
Functions.php
<?php
function loadView($viename,$meta=[]){
//load footer/header page
include_once "common/$viename.php";
}
//any other functions
The loadView() function is used anytime you want to load these two dynamic files. This functions takes two parameters 1 optional. The first parameter is the name of the view you want to load which is header or footer then the second optional is the meta information important for the header file, as the page title and meta description needs to be dynamic and change according to the page.
header.php
<!DOCTYPE html>
<html>
<head>
<title><?=$meta['pagetitle']?><!-- Dynamic page title --></title>
<meta name="description" content="<?=$meta['pagedescription']?>"><!-- Dynamic description -->
<!-- load your styles -->
</head>
<body>
<header>
<nav>
<!-- Your page navigation -->
<ul>
<li>Home</li>
<li>About</li>
<li>Another Page
</ul>
</nav>
</header>
footer.php
<footer>
footer content
<p>© website name <?=date('Y')?>
</footer>
</body>
</html>
Main website pages
Your main website pages are pages such as index, about,services etc.
In these pages you would load the functions file, then be able to load the header and footer.
index.php
<?php
include 'includes/functions.php';
//meta info
$meta = array(
'pagetitle' => 'Welcome to my site | site | bla bla',
'pagedescription' => 'This is your website description'
);
loadview('header',$meta); //load heade
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<?php
loadview("footer"); //load footer
?>
About Page
<?php
include 'includes/functions.php';
$meta = array(
'pagetitle' => 'About Us',
'pagedescription' => 'This is about page'
);
loadview('header',$meta);
?>
<section>
<div id="content">
<p>Page Content</p>
</div>
</section>
<!-- load footer -->
<?php
loadview("footer");
?>
Hope this gives you the idea on how you could achieve your goal, there are many ways you can achieve this.
Let me know when you need any help
Assign values for $h_path and $f_path dynamically.
<?php
$h_path = '';
$f_path = '';
include($h_path.'header.php');
include($f_path.'footer.php');
?>
My apologies for not providing enough information about the issues. My issue is that, when the index.php refers to the header and footer by "includes/header.php" and "includes/footer.php" respectively, and other webpages are located inside another folder which needs to access the includes folder via "../includes/header.php". There is no problem while referring to the files but the issue occurs when headers.php targets the webpages inside when it is written to only work with index.php. For example, would only work on index.php but not on the php files inside the folder which needs , But I'll try with $h_path = ''; and $f_path = '' soon.

WordPress One Page scroll website - how to?

I need some help to understand how to create WordPress One Page Scroll website. I did a standard website before (the one that change content after clicking on menu link), but I can't figure out how to use WP on web page with scroll to section instead of standard sub-sites.
Let me show You structure of my site:
<!DOCTYPE html>
<head>
css/bootstrap
css/main.css
etc.
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top" id="navbar">
//This navbar overlaps header and it's fixed to top//
//Has links to sections (e.g. #one, #two etc.)//
</nav>
<header class="masthead">
//This is also my "front page" displayed on page load with height:
100%, width: 100%//
</header>
<section id="one" class="bg-primary">
//first section to scroll to//
</section>
<section id="two" class="bg-primary">
//second section to scroll to//
</section>
//first section to scroll to//
<section id="three" class="bg-primary">
//third section to scroll to//
</section>
<footer id="main-footer" class="bg-primary">
//Some info about author, website, and social media links//
</footer>
js/jquery.min.js
js/bootstrap.min.js
js/script.js //my custom scripts
</body>
My problem is- how to organize this content for CMS to change every section content via dashboard?
1. Should I create different page.php for each section (e.g. page-one.php etc) and use:
<?php get_header(); ?>
<?php get_template_part('page-offer'); ?>
<?php get_template_part('page-tech'); ?>
<?php get_template_part('page-portfolio'); ?>
<?php get_template_part('page-contact'); ?>
<?php get_footer(); ?>`
on index.php
Or should I create section-one.php, section-two.php etc. and display it on "front-page.php"?
My second question is- is it possible to create different PHP file with Navbar code, and use this navbars html, and css as WordPress dashboard menu? Or should I create menu in dashboard first (every section is a single page) and then style it with custom css?
And last: How to use custom fields to edit every single paragraph, button content, link etc. via dashboard and allow it to work with POLYLANG to change content language?
Thanks for any help, and apologize for long thread. I'm realy struggling with this.

Removing class in WordPress plugins file - not working without page refresh for the first time

I have a class called event-manager in a wordpress php file in the plugins folder. They are using this class to style the elements, and I am using a custom css to over-write this. The problem is I cannot overwrite their css so I had to remove this class all-together.
I need to remove this class dynamically, removing manually every-time is pointless, because every-time the plugin gets updated the class comes back.
And here the html structure. The class appears on two different pages and on both pages the image alignment is different.
<!-- Home page -->
<div class="some-class">
<div class="some-more-class">
<div class="featured-image"> <!-- this image alignment is different -->
<div class="event-image"> <!-- this div is generated dynamically from the plugin -->
some link
</div>
</div>
</div>
</div>
<!-- Blog single -->
<div class="some-class">
<div class="some-more-class">
<div class="featured-img"> <!-- and image alignment is different -->
<div class="event-image"> <!-- this div is generated dynamically from the plugin -->
some link
</div>
</div>
</div>
</div>
To acheive this I used jquery .removeClass method.
$(function(){
$(".featured-img > div, .featured-image > div").removeClass("event-manager");
});
I also tried this
$(function(){
$(".featured-img > div").removeClass("event-image");
$(".featured-image > div").removeClass("event-image");
});
And this
var featuredimg = ['.featured-img > div','.featured-image > div'];
$(featuredimg.join()).removeClass('event-image');
On all these methods, the class seems to be removed, because its on two different pages, when I load the homepage.php for the first time, the class is removed but when I go to single.php, it did not remove automatically and when I refresh the page, the class removes. I am not sure why.
Can anyone help me.
Thanks.
In my opinions it is related with caching. Do you have any? If yes disable it to test if works without it. If no you can check on developer console if do you have any errors. Issue can be also with place the script like this (prefer at the end of the page).

How to include and link menu file into every webpage using HTML?

I have researched some answers that talk about php, javascript, iframes etc. but I have tried a couple and none of them work. I am new to HTML coding.. and coding in general!
<link rel="menu" href="menu.html"> does nothing
<!--#include virtual="/menu.html" --> does nothing (presumably because its a comment?)
<iframe src="page.html"></iframe>
or object... both place the menu in a silly little scroll box.
I want to run my menu on my page as if it were a function in C. Where I can just include it, and it be there, or just link it.
Thanks for the help!
Ryan
webpage file: biology.html
menu file: menu.html
<div class="container">
<img src="homeicon.jpg" width="50" alt="Home">
<div class="redhover">
<div class="dropdown">
<button class="dropbtn">GCSEs</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">A-Levels</button>
<div class="dropdown-content">
Chemistry
Biology
</div>
</div>
<div class="dropdown">
<button class="dropbtn">University</button>
<div class="dropdown-content">
Telecommunications
Electronic Engineering
</div>
</div>
<div class="dropdown">
<button class="dropbtn">More</button>
<div class="dropdown-content">
About me
Youtube
</div>
</div>
</div>
</div>
You can use php to include files on other pages. Here is some example code to get you started:
<?php
require_once('menu.php');
?>
You can put this in your HTML page appropriately, however you must make sure that php can be processed on your server and the file containing php code must end in the .php extension.
There are also other methods of including files via php, see here:
http://php.net/manual/en/function.include.php
and
http://php.net/manual/en/function.require.php
Edit - I'm not a big fan of this approach, but it will work on Github pages.
Create a file called nav.js with your menu defined as a js variable, then use javascript to insert it into an empty div created on each page. This way to update your nav you only have to ever edit nav.js Not pretty but it works
nav.js
var navigation = "<nav>";
navigation += "<ul>";
navigation += "<li>Home</li>";
navigation += "<li>About</li>";
navigation += "</ul>";
navigation += "</nav>";
document.getElementById("navigation").innerHTML = navigation;
Other pages
<div id="navigation"></div>
<!--rest of page goes here.-->
<script src="nav.js"></script>
Fiddle: https://jsfiddle.net/ze3hLxx8/1/
There are multiple ways to include a file into another depending on the backend technology you wish / want / need to use.
PHP
The most common way to do it in php is by using the include or require statement inside a php file.
In your specific case your biology.html file must be converted to a biology.php file and then you can add the relative code to include the file:
<?php include('menu.php');?>
This simple statement will add the content in your menu.php file to the current page. This will not work if php is not present on the server and obviously will not work locally without a local development environment
The differences between require and include can be found on the official documentation:
include: http://php.net/manual/en/function.include.php
require: http://php.net/manual/en/function.require.php
SSI
Another method is to use Server Side Includes. To use the SSI it must be supported and enabled on the webserver. To use SSI you need to change the extension from biology.html to biology.shtml and then add the following statement:
<!--#include file="menu.html" -->
More information on server side includes can be found on wikipedia: https://en.wikipedia.org/wiki/Server_Side_Includes

Dynamic data in header in a symfony project

I have a Symfony 1.4 project. As you know the Template layout is defined independently, in the apps' templates' folder and then it is universally applied to all other templates. My layout is very simple, something like this:
<div id = "header">
</div>
<div id = "content">
<?php echo $sf_content ; ?>
</div>
<div id = "footer">
</div>
$sf_content, as most symfonians would know, essentially spits out the template for whatever web page is being viewed at the moment. If I needed some specific data for my header, such as logout, logo etc, I would simply include it within my header. THis works great because it is static in nature. The challenge I am facing is how I can include data that is dynamic in nature and specific to a page within the header tag because the UI demands that I include it there.
For instance, one of my webpages requires user specific data to be loaded in a dropdown/select menu. This is dynamic and could range from 0 to 100 and is specific to each user. To create this dropdown menu is not an issue, and I already have that part done. The challenge is, how do I load it in the header, given that my data becomes part of $sf_content and that is spit out in my content div.
Is there a way for me to move a specific part of my $sf_content into the header div ?
In your actions.php:
$this->getResponse()->setSlot('someData', 'and its value');
In layout.php:
<div id="header">
<?php echo get_slot('someData'); ?>
</div>
<div id="content">
<?php echo $sf_content ; ?>
</div>
<div id="footer">
</div>
Slots work for this. They can either be set in the action as in the first answer above or you can define them in the templates themselves. This is what I've done where I have dynamic data to define for the layout.
In your example:
<div id="header">
<?php include_slot('some slot name')?>
</div>
<div id="content">
<?php echo $sf_content() ?>
</div>
<div id="footer">
</div>
In the templates you would define the following:
<?php slot('some slot name')?>
//your code goes here
<?php end_slot() ?>
When the layout is then rendered Symfony will place the code between the slot() and end_slot() into the point at which you defined by using include_slot().
For ease I created a global partial that is included in all templates that defines the various common slots used through out the application. There is more info on slots and their usage here

Categories