### Adding a New Page.txt ### version 2.1.1 Weather Website PHP Scripts from Silver Acorn These programs are distributed in the hope that they may be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. !!! There is NO guaranteed support !!! ################################################################################ TOPICS A. A NUMBER OF FACTORS SHOULD BE CONSIDERED B. NOTES ABOUT "LOOK AND FEEL", AND ALL THOSE FILES BEING LOADED AT THE BEGINNING OF THE PAGE. C. ACCESSING FILES IN ANOTHER FOLDER D. LINKING TO OTHER WEBSITES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A. A NUMBER OF FACTORS SHOULD BE CONSIDERED 1. Do you know what you are doing? A wrong step can stop a website! View the other pages to see how the pages are constructed - there is a variety to suit the individual page content. 2. To have your new page display in the menu, and be activated from the menu:- a. Make a copy of the file new_page.php saving it with the name you wish to appear on the menu. or, make a copy of an existing page, saving it as newname.php, and edit it. b. Note that newname.php requires settings.php, nav_menu.php and footer.php. settings.php does not require editing but must be loaded at the top of the new page. nav_menu.php requires editing to add newname.php to the site. However, newname.php can be tested before adding it to the menu by changing the url in the browser. https://sitename/newname.php Once newname.php is working:- i. Decide on the position in the menu. ii. Edit nav_menu.php by copying the existing entry above the newname.php menu location to immediately below the existing entry. e.g. copy
  • > Now
  • and paste
  • > Now
  • to the new location, and edit it
  • > Newname
  • iii. If there is no newname.css file, rem out the css entry above BUT you will probably require a simple newname.css file in the css folder to correctly position the page just below the nav_menu - see ./css/index.css for an example. e.g. If importing an existing page from elsewhere which has a block in it, this can be left in place for testing. Once the page is working, in the css folder, create a new file newname.css and move the block into the new newname.css file remove from the new .css file. remove the from and test. Size and colors are the most likely css items requiring change to fit the style of this website. iv. The , and blocks should remain as they provide the look and feel of the site. If overrides to the style are required, make the changes by adding to or editing newname.css v. is used to include any data files or additional code blocks that are not created directly in newname.php ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ B. NOTES ABOUT "LOOK AND FEEL", AND ALL THOSE FILES BEING LOADED AT THE BEGINNING OF THE PAGE. "look and feel" If you are introducing an existing file from another source, the first thing to address is to make it look like the rest of the site Tables Add
    immediately before with matching immediately after
    controls the width of the table and matches it to the nav_menu width, and makes it responsive
    provides the matching background colour to the nav_menu and the rest of the site. If there are multiple separate tables then depending on the layout, a new
    set may be required around each table. As noted in new_page.php, Not every one of the may be required. check other pages that are similar to the one you are creating and use that set first. You can rem them out one at a time and see what affect they have on the new page If you are adding a language, check a page that most looks like the new page and follow how it is configured in settings and nav_menu NOTE that with style/css , a style always over rides one that came before, so sometimes there are repeating declarations in different blocks of a page as an earlier block may have required a specific style. C. ACCESSING FILES IN ANOTHER FOLDER If filename.ext is in a subfolder, e.g. /mxtest/subfolder/filename.ext then to access a file in subfolder from mxtest, the include should be - single quotes may be required in some situations but usually it does not matter which is used (provided the pair is the same!). The ./ means only look in this level If filename.ext is in a folder at the same level as mxtest, e.g. . . /mxtest/subfolder/filename.ext /samelevel/filename.ext . . then to access a file in samelevel from mxtest, the include should be - single quotes may be required in some situations but usually it does not matter which is used (provided the pair is the same!). the ../ means go up one level Note that include_once( ) and require_once( ) ensure that the file is loaded once and is accessible to other pages, and if called again in another page it will not be loaded again but the existing loaded file will be used. If you are not sure which to use, google it, or see below for a shortened version of what is in the link(s) below https://www.php.net/manual/en/function.include.php include (PHP 4, PHP 5, PHP 7) The include statement includes and evaluates the specified file. The documentation below also applies to require. Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include will finally check in the calling script's own directory and the current working directory before failing. The include construct will emit an E_WARNING if it cannot find a file; this is different behavior from require, which will emit an E_ERROR. If a path is defined — whether absolute (starting with a drive letter or \ on Windows, or / on Unix/Linux systems) or relative to the current directory (starting with . or ..) — the include_path will be ignored altogether. For example, if a filename begins with ../, the parser will look in the parent directory to find the requested file. https://www.php.net/manual/en/function.include-once.php include_once (PHP 4, PHP 5, PHP 7) The include_once statement includes and evaluates the specified file during the execution of the script. This is a behavior similar to the include statement, with the only difference being that if the code from a file has already been included, it will not be included again, and include_once returns TRUE. As the name suggests, the file will be included just once. include_once may be used in cases where the same file might be included and evaluated more than once during a particular execution of a script, so in this case it may help avoid problems such as function redefinitions, variable value reassignments, etc. https://www.php.net/manual/en/function.require.php require ¶ (PHP 4, PHP 5, PHP 7) require is identical to include except upon failure it will also produce a fatal E_COMPILE_ERROR level error. In other words, it will halt the script whereas include only emits a warning (E_WARNING) which allows the script to continue. https://www.php.net/manual/en/function.require-once.php require_once ¶ (PHP 4, PHP 5, PHP 7) The require_once statement is identical to require except PHP will check if the file has already been included, and if so, not include (require) it again. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ DROP DOWN MENU ITEM:- Adding a drop down menu item to provide a list of additional pages / links. nav_menu.php contains an example of a drop down menu - Davis Live Consoles First create a working new page in the site as detailed above. Test it by opening it directly on the url of your site. Once you have a working stand alone page, then it can be added to a dropdown menu. The structure is:- ';} else {echo ' The basic structure is an unsorted list
  • The two lines ';} else {echo '
  • > New Page3.php
  • creates the menu item in the drop down list. the final closes out the outer list structure. So there is
    • .. page1 ..
    • .. page2 ..
    • .. page3 ..
    • .. etc ..
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ D. LINKING TO OTHER WEBSITES links_singledropdn.html There is an example of a menu structure in the file links_singledropdn.html which is (included) into the nav_menu. Here is an example of two ways to add links to another website. a. The first links directly to another site in the same domain. b. The third links to a remote site using the full URL The changes are made in nav_menu.php Near the end of the file - immediately BEFORE this code at the end of the file,
    Insert this block of code (including a blank line before and after - makes it easier avoid errors!) Then, replace the "....." in ..... to suit your requirements. Any number of
  • > .....
  • links may be added. The first example links out through the internet so may be slower in operation The second example links to a website in the same domain. NOTE:- this structure is different from the others as there is no $page_id so there is some dummy code to enable the