Dynamic websites using php without inclusion - php

I am developing a website where all 5 main pages(home, about me, contact, blog, my foundation) are structured different from each other so I dont want to use the include() function to inherit anything from the index. how do I go about going to these pages about me (home, about me, contact, blog, my foundation)

You will need to add a link from each page to every page. It would be best to create a header.php file which you would include on every page. This file would contain your 'navigation' or the links to all the other pages. Since you say you don't want to use includes you will have to add this same code at the top of all the pages. If you want to change them you will have to change them on every page. If you used the include() function instead you would only have to change it once.

Related

How to send a variable into an included php-file that's nested in a php-file

I have a nav-bar with 3 link's. I used to keep the navbar within my 3 pages but someone suggested to use one navbar.php with that navbar code and include that file within all other files that use the navbar. So, less code, same result. And it works.
However, I was using aria-current="page" to highlight the link on the active page. But now that doesn't work anymore.
I found some similar pages with that question but it puzzles me. I am relatively new to all this so I hoped one could make it not only clear but crystal-clear to me.
I found this page :
PHP Pass variable to next page
and so I used this code already to get info to navbar.php.
(https://i.stack.imgur.com/ne5FI.png)
So , all things start on my index.php page where I use a navbar.php which contains my navbar.
I can move to page 'about', 'portfolio' or 'contact' with one of the three links provided in navbar.php.
On index.php none of the three links are highlighted of course because I'm not on one of those pages.
Now, when I am going to page 2 'about'. I want to give that info "$active_var=2" into navbar.php which will return a different outcome on the highlight of a 'href' with aria-current="page". The link 'about' will be fatter.
Same for the other pages.
I think i need to declare the variable in the navbar.php only. and then give a value when clicking on a link. That info will go to the corresponding page ex. about.php but that i'm not sure.
Here is my navbar code :
I left the code for the link to about.php like it was and changed the code for the other two links like I think they should be, but it doesn't work.
enter image description here
I hope I was clear enough myself in my question.
tried inserting info from a variable but don't see how because I use a php with a include navbar.php which needs info from the parent php. I might not understand which page needs which var info. So I am on index.php with 3 links to other php's which all have the include navbar.php that has the code for making the links and highlighting the current page.

Wordpress include php file

I am trying to create a php website on WordPress for the first time.
When I create a page, it creates a permalink which is of the form http://localhost/?p=123. I don't know if there is a corresponding file.
I've installed insert-php plugin to read php code. It works fine on a static page. But how do I include another php file? I want to include my_utilities which contains all the back-end functions, in login. It has a permalink 'http://localhost/?page_id=45'.
What to do?
include 'http://localhost/?page_id=45' doesn't work.
Pages you define in WordPress's backend are pages mostly setup for your users to view / read. They, by default, have this URL structure of http://localhost/?p=123 (though this can be changed, but that's a whole different lesson).
To include a script file, upload the file to your folder structure where you have your website then refer to it in your include statement as follows:
include('path/to/folder/my_script.php');
EDIT: You may also want to have a look into WordPress Page Templates:
Pages are one of WordPress's built-in Post Types. You'll probably want most of your website Pages to look about the same. Sometimes, though, you may need a specific Page, or a group of Pages, to display or behave differently. This is easily accomplished with Page Templates.
For exapmle your wordpress file is at
/var/www/html/wp-content/myphpfiles/test.php
To include the test.php file in your wordpress page you have to following.
[insert_php] include('wp-content/myphpfiles/test.php'); [/insert_php]
Thats it.

Yii Page Variation

I have a website that needs to have a variation of pages.
For example:
website.com/variation1/page1
website.com/variation2/page1
website.com/variation3/page1
All of which has the same DB and has the same function. The only difference is that these variations differs in page template ie. Header, Footer, Content, etc. This is for the purpose of analyzing page visits.
With that, what is the best way to do this? In Yii, there is a common layout used so header/footer depends on the layout. In this case, the header/footer should be specific to each page so the user can just modify the header/footer/content of a specific page without affecting other pages.
So, again what is the best approach for this?
Thank you in advance.
EDIT:
I think I know what I'm looking for here:
Is there a way to override/add from a layout the header in a view file?
Create Three different layouts say variation1.php, variation2.php, variation3.php, then based on the action(website.com/variation/pageone) or the parameter(website.com/variation/page/1) change the layout(in action).
I just found out a possible solution to approach page variations.
Under my view directory I created a directory varation which contains the pages i.e.
/view/variation/1/page1.php
/view/variation/2/page1.php
So when I want to render the varations I'll call each in the controller with parameters included.
Ex. $this->render('variation/1/page1') somewhat.
And in each page if you want to use a specific header info you may use
Register Meta Tag
Register Script File / Script
Register CSS File / CSS
Let me know if there are better ways of doing this.

Test custom header in Drupal before publishing

I'm quite new to Drupal and want do some editing of the header. I want a custom toolbar to appear on every page. I've already created that toolbar in a file called toolbar.php. It has a layer which is fixed and will appear on top of every page.
How do I include the toolbar.php in the header template of drupal?
The toolbar refers to $user which is a global Drupal variable and I want to test toolbar.php before publishing it to the site. Is there anyway I can do that?
Regards,
Dasith
Of the two methods above the first is easier if you understand the basic idea of html and CMS templates, the second will be easier if you are a programmer.
First thing to check is that you really need to do this! Can't you restyle one of the existing menus (Primary or secondary) to do this - will make your life (and anyone who works on the site in the future) a lot easier.
The other thing you can do is look into adding an output region, basically something where you put the php into a drupal friendly format and then effectively do a 'drupal print'. This is how the toolbar, search box etc are done. You still need to alter the templates as above.
Yes for sure. If you want to have the html produced by your function/file appear on every page of the site then you will need to over-ride the page.tpl.php file in the theme you are using and essentually add the html to that file.
To gain access to the $user variable, just declare it in your script.
global $user;
open page.tpl.php file in a code editor and save as page-front.tpl.php (with two dashes if you are using Drupal 7.. one dash with Drupal 6) and upload it to your theme's directory. Clear your cache by going to configuration->Performance->Clear All Cache. Then referesh the page. Now your homepage is using page-front.tpl.php as it's template file. Every page will need its own template file. The page machine name comes after the hyphen so the user page template uses page-user.tpl.php. You can edit it as you want. The proper way to really do this is to use hook_theme() to pass variables to the template file. One variable could be the html which creates your custom header.
See also http://drupal.org/node/457740 Beginners Guide to over riding theme output

Include menu on every page

Let's say I have a simple CSS layout and my menu is a column on the side. This menu is going to be on every web page (About 10 web pages). If I have items on this menu in the form of links and such, how can I make it so that if I add a link on one page, it will add it to all pages? Would you just make it a PHP page and in that <div> element include a PHP file called menu or something, and just edit that PHP file (so I only have to edit that file and not every web page)?
If this is raw PHP (no frameworks) then you simply include it.
include('sidebar.php');
Make sure that you can access the file from where you are including it though. If you have files in a folder called foo for example, and accessed via example.com/foo/somefile.php you will have to change the include statement to include('../sidebar.php'); assuming sidebar.php is in the root.
As stated above, and include would do.
Drop this on every page you want your menu to appear:
<?php include("/yourMenu.php"); ?>
Just save the menu code as yourMenu.php and put it in the root and you are good to go.
i've used this trick before and it works well. you can use this in conjunction with an include php
Intelligent Navigation
If you are using the Apache web server it's even more simple and faster to use server side include (ssi). You can do the same for the footer and other common areas of your pages.
Here is the reference page: http://httpd.apache.org/docs/2.2/howto/ssi.html

Categories