Add link php links

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

PHP template allows linking to any folder or file without manually navigating up directories with ../

SleekPanther/php-magic-linking

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

PHP Magic Linking Template

NEVER WORRY ABOUT PUTTING ../ BEFORE LINKS EVER AGAIN!

You often store each page in a separate folder to allow more readable URLs. Instead of mySite.com/about_us_page.php , you want mySite.com/about . So put an index.php in the folder about/ ( mySite.com/about is equivalent to mySite.com/about/index.php )

You can have multiple sub-directories: a main Gallery Page mySite.com/gallery that lists the individual sub-galleries like mySite.com/gallery/indoor or mySite.com/gallery/outdoor

But you run into trouble linking between pages. Small sites can get away with index.php , about.php , gallery1.php , gallery2.php etc. in the same folder, but it’s not organized or scalable. If all pages were in the same folder, you could use 1 copy of global navigation called nav.php & use a php include to keep the navigation consistent. But nested sub-directories cause problems.

A cheater «solution» is to have a copy of nav.php for each level of directories
DON’T TRY THIS! Trust me, it’s a pain to maintain 3 copies of nav.php when you just want to change 1 link.

The Situation (Problematic Linking)

  • Act as if all links start in the root folder (where theHomepageis)
  • This code analyzes the URL to find how many folders below the root directory the current page is
  • Add before any link
  • The manual link fromAbouttoHomeHome
  • Becomes Home & will work from any level directory
  • Code in top.php magically prints the correct number of ../ in your link

Major Features (click link to jump to section)

  1. Link to any page without using ../ EVER AGAIN!
    (also applies to css, images & any files on your site)
  2. Consistent nav on all pages (using the same php include )
  3. Identify the current page & highlight the current link in nav menu (so the user knows where they are)
  4. Automatic Breadcrumb links
  5. Automatic Meta descriptions stored in easily-editable text file
  6. Tags that match the current page
  7. Print the page name in automatically (no hard-coding)
  8. Print unique IDs for each page in tags
    Use css toapply styles to only 1 page
  • Every viewable page should be called index.php
  • But MUST HAVE UNIQUE PARENT FOLDER
    (Since all pages are index.php , a file’s parent folder/containing folder is VERY important to identify the current page)
  • Folder names should be lowercase, NO SPACES
  • Folder names BECOME thePage Title (stored in $pageTitle
  1. — (hyphen characters) will be replaced with / (forward-slashes)
  2. _ (underscores) will be replaced with spaces
  3. First letter of each word will be Capitalized
Читайте также:  Serversocket methods in java

Example:
The folder «our_prices-services» becomes «Our Prices / Services»
Search/ Ctrl+F «convFolder2PgTitle» in top.php to edit the function. (Maybe you don’t want to replace underscores)

This Project’s Default Folder Setup (what files go where)

  • The Homepage goes in your site’s root directory (default is php-magic-linking for THIS project)
  • about/index.php gets its own folder since it’s on the same level of the nav as Home
  • portfolio/index.php and tests/index.php are also on the same level of the nav as Home
    (They’re mostly placeholder pages used for breadcrumb trails)
  • portfolio/portfolio_1/index.php and tests/test_1/index.php are 1-level dropdown pages
  • portfolio/examples/example_1/index.php is a 2nd-level dropdown page
  • images/ contains ALL images
    There are many ways to organize your images, so modify as you wish
  • non-pages/ contains anything that ISN’T a complete page
  • php-include/ has partial components that are assembled to create complete pages
  • css/ has the stylesheets
  • descriptions/ has a text file for Meta tag page descriptions

Finding Your Root directory ( $ROOT_DIRECTORY variable)

  • Upload setup.php to your web server & view the page
  • Or just view setup.php on localhost
  • This tells you the containing folder (like pwd in command line ), the value you should store in $ROOT_DIRECTORY
  • Some common folders are public_html or www-root

THINGS YOU MUST EDIT!

  • Rename php-magic-linking to your site’s root directory(found just above)
  • Edit line 12 in top.php to match
    $ROOT_DIRECTORY = «php-magic-linking»; (this should match, or be changed)
  • IF YOUR ROOT DIRECTORY HAS A PARENT FOLDER WITH THEEXACT SAME NAME
  • (e.g. $ROOT_DIRECTORY is my-folder but the complete path is mysite.com/my-folder/dev/site1/my-folder
  • Notice 2 occurrences of my-folder
  • Search/ Ctrl+F for the line: for ($i = 0; $i < count($split_url); $i++)
  • Look 3 lines later for break;
  • COMMENT OUT OR REMOVE the break;
  • Every page must manually link to top.php BEFORE ANY OTHER PHP CODE!
    This allows you to use $upFolderPlaceholder later in the page
  • Homepage link:
  • 1 folder Level below homepage (e.g. /about/index.php , /portfolio/index.php etc.) is
  • 2 Levels below (e.g. /portfolio/examples/index.php ) is
  • 3 Levels below (e.g. /portfolio/examples/example_1/index.php ) is
  • Search/ Ctrl+F «36714768356» in top.php (section to list all YOUR pages)
  1. Put all top-level pages (including $ROOT_DIRECTORY for Homepage) in $pageArrayTop
    $pageArrayTop = array($ROOT_DIRECTORY, ‘portfolio’, ‘tests’, ‘about’); //this is the default code
    Replace with your pages, EXACT FOLDER NAMES (case sensitive)
  2. Put ALL 1st-level-dropdown pages in $pageArrayDropDown1
    $pageArrayDropDown1 = array (‘portfolio_1’, ‘portfolio_2’, ‘examples’, ‘test_1’, ‘test_2’); //default code
  3. Put ALL 2nd-level-dropdown pages in $pageArrayDropDown1
    $pageArrayDropDown2 = array (‘example_1’); //default code
  • ORDER DOESN’T MATTER, but don’t leave out any pages!

More Optional Things To Edit

  • Replace default Favicon in images/0_components/favicon.png
    images/0_components/favicon.png»> in top.php
  • Replace default logo in images/logo/logo.png
    Search for in nav.php to see where it’s used
  • Update to your name/company in top.php
  • Add your site’s tagline
    $tagLine = » — Your Tagline»; in top.php
    This appears in the tag. Like » — Wikipedia, the free encyclopedia» at the end of every Wikipedia Page
  • Breadcrumbs are optional. To remove: Simply delete or move the
    .

    tag in header.php

  • Add page descriptions to appear in
    (You edit non-pages/descriptions/descriptions.txt JUMP TO DETAILS SECTION ⇓)

Page Structure (Anatomy of a Page, PHP Includes)

Viewable pages constructed from partials in non-pages/php-include/ as follows:

  1. top.php begins the HTML file. It has everything in the section & important URL magic happens here
    It uses 2 php includes at the end to render nav.php and header.php
  2. nav.php contains Global Navigation (1 copy for all pages)
  3. header.php can contain a Global logo, site title, slideshow, etc.
    CURRENTLY IT ALSO CONTAINS Breadcrumbs. See details to remove them ⇓
    tag is opened in header.php but closed in each index.php page
  4. Unique page content goes in each index.php file (e.g. homepage, about, etc.)
    Must include the Footer near end
  5. footer.php is for any content you want at the bottom of every page
  • Feel free to rearrange the php includes but make sure the tags are nested correctly
  • Notably, opening in header.php , currently closed in each index.php page**
  • View Page Source & look for HTML comments like and
    If the PHP includes are confusing, this helps show how render the actual page

Источник

Оцените статью