automatic page nav change

  • Bogey
  • Bogey
  • Genius
  • User avatar
  • Joined: Jul 14, 2005
  • Posts: 8211
  • Loc: USA
  • Status: Offline

Post April 6th, 2010, 7:09 pm

I don't know if this was answered adequately, but I think I have a better way to come about this after reading the first four posts.

Here is how I would do it... (The code looks a lot better if you download it and open it with Notepad or Notepad++ or something).

PHP Code: [ Select ]
<?php
// Page name
$page_name = ltrim($_SERVER["PHP_SELF"],'/');
$page_name = rtrim($page_name,'.php');
 
// Default footer text
$footer = '© 2010 Melted, LLC';
 
/*
    The pages...
   
    You could have different things for different pages...
    like what I got going with 'css' and 'title' for each page.
   
    That could be useful for things like javascript and other things
    that are page specific or things that other pages just don't need.
   
    I'm expecting here that each page would have it's own CSS and title
    element, so I coded in the process after the array that processes
    those things. If you are going to have something that is page
    specific and wouldn't be defined or neccessary to define elsewhere,
    you could use a conditional statement like I did with 'footer' and
    'image'.
*/
$pages = array(
            'index' => array('css' => '#div_name' => array('background-color' => '#fc0000',
                                                           'font-color' => '#000000'
                                                         ),
                                      'div[class].active_pages' => array('float' => 'right'
                                                         ),
                             'title' => 'Page Title for Index'
                            ),
            'contact'   => array('css' => 'p' => array('background-color' => '#fc0000',
                                                       'font-color' => '#000000'
                                                         ),
                                 'title' => 'Page Title for Contact',
                                 'image' => '<img src="path/to/img.png" alt="An image" />' // This would be written into the HTML part of the code... no need for additional PHP
                                ),
            'guestbook' => array('css' => 'span#name' => array('background-color' => '#fc0000',
                                                               'font-color' => '#000000'
                                                         ),
                                 'title' => 'Page Title for Guestbook',
                                 'footer' => 'Driven by Bigwebmaster © 2010 Bigwebmaster.com',
                                )
);
 
// Getting the page title for the pages
$page_title = (isset($pages[$page_name]['title'])) ? $pages[$page_name]['title'] : 'Welcome';
 
// Generating the CSS for this page
$css = null;
foreach($pages[$page_name]['css'] as $css_element => $css_components)
{
    $css .= $css_element . ' {\n';
    foreach($css_components as $css_rule => $css_value)
    {
        $css .= "     {$css_rule}: {$css_value};\n";
    }
    $css .= '}\n\n';
}
$css = trim($css);
 
// Generating the footer
$footer = (isset($pages[$page_name]['footer'])) ? $pages[$page_name]['footer'] : $footer;
 
?>
  1. <?php
  2. // Page name
  3. $page_name = ltrim($_SERVER["PHP_SELF"],'/');
  4. $page_name = rtrim($page_name,'.php');
  5.  
  6. // Default footer text
  7. $footer = '© 2010 Melted, LLC';
  8.  
  9. /*
  10.     The pages...
  11.    
  12.     You could have different things for different pages...
  13.     like what I got going with 'css' and 'title' for each page.
  14.    
  15.     That could be useful for things like javascript and other things
  16.     that are page specific or things that other pages just don't need.
  17.    
  18.     I'm expecting here that each page would have it's own CSS and title
  19.     element, so I coded in the process after the array that processes
  20.     those things. If you are going to have something that is page
  21.     specific and wouldn't be defined or neccessary to define elsewhere,
  22.     you could use a conditional statement like I did with 'footer' and
  23.     'image'.
  24. */
  25. $pages = array(
  26.             'index' => array('css' => '#div_name' => array('background-color' => '#fc0000',
  27.                                                            'font-color' => '#000000'
  28.                                                          ),
  29.                                       'div[class].active_pages' => array('float' => 'right'
  30.                                                          ),
  31.                              'title' => 'Page Title for Index'
  32.                             ),
  33.             'contact'   => array('css' => 'p' => array('background-color' => '#fc0000',
  34.                                                        'font-color' => '#000000'
  35.                                                          ),
  36.                                  'title' => 'Page Title for Contact',
  37.                                  'image' => '<img src="path/to/img.png" alt="An image" />' // This would be written into the HTML part of the code... no need for additional PHP
  38.                                 ),
  39.             'guestbook' => array('css' => 'span#name' => array('background-color' => '#fc0000',
  40.                                                                'font-color' => '#000000'
  41.                                                          ),
  42.                                  'title' => 'Page Title for Guestbook',
  43.                                  'footer' => 'Driven by Bigwebmaster © 2010 Bigwebmaster.com',
  44.                                 )
  45. );
  46.  
  47. // Getting the page title for the pages
  48. $page_title = (isset($pages[$page_name]['title'])) ? $pages[$page_name]['title'] : 'Welcome';
  49.  
  50. // Generating the CSS for this page
  51. $css = null;
  52. foreach($pages[$page_name]['css'] as $css_element => $css_components)
  53. {
  54.     $css .= $css_element . ' {\n';
  55.     foreach($css_components as $css_rule => $css_value)
  56.     {
  57.         $css .= "     {$css_rule}: {$css_value};\n";
  58.     }
  59.     $css .= '}\n\n';
  60. }
  61. $css = trim($css);
  62.  
  63. // Generating the footer
  64. $footer = (isset($pages[$page_name]['footer'])) ? $pages[$page_name]['footer'] : $footer;
  65.  
  66. ?>


I don't really understand what you mean by other questions you had, but I think that this should help you out a little.

The CSS in the PHP thing should be used to over-ride the css written in the actual stylesheet... unless you want to use this way as the main way. Your choice.

Hope that this helped you out a bit :)
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post April 6th, 2010, 7:09 pm

  • SB
  • Moderator
  • Genius
  • User avatar
  • Joined: Nov 16, 2004
  • Posts: 8670
  • Loc: Aberdeen, Scotland
  • Status: Offline

Post April 7th, 2010, 9:15 am

The sooner i get this site out of the way the better. I really don't understand what you have just typed Bogey, so trying to work that into the code i currently have is proving to be a bit more irritating than i would like...which is not your fault.

I am very tempted to create a topic in the marketplace forum advertising this site as a job. It may be simple to everyone else but it's just way beyond me and the lack of time i have to actually complete it is also proving to be a pain in the ass.

Thanks for your help Spoof & Bogey.

Post Information

  • Total Posts in this topic: 17 posts
  • Users browsing this forum: Kurthead+1 and 168 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.