SitePoint Sponsor

User Tag List

Results 1 to 18 of 18
  1. #1
    SitePoint Enthusiast kajax101's Avatar
    Join Date
    Apr 2004
    Location
    London UK
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Dynamic CSS website, how do I do it?

    Hi,

    I'd like to create a website that using CSS, that part I understand, the part I don't is how to make a website the website easiliy maintainable.

    Dynamic menus (using xml for example) make a site much easier to maintain, you simple edit and upload one file and site-wide the menu changes.

    What is the easiet way to implement something like this?

    Using ASP? Using .Net? I'm really not too experienced with this sort of thing, but I'd really like to use XML.

    Cany anyone help?

  2. #2
    SitePoint Member eustace's Avatar
    Join Date
    Dec 2004
    Location
    dublin, ireland
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recently got into using CSS, XHTML,PHP and Smarty. I think this is a great combo, you have your content(HTML) separate from the design(CSS) and it complies well with w3c standards. The use of PHP and smarty means you can use templates in your sites which make it alot faster and easier to maintain. In my site I have a header file, a main content file and a footer file. So if I want to update content generally its just a matter of copying it into a new template file and linking it up. I don't have much experience with plain XML so I can't comment on that to much.

  3. #3
    SitePoint Enthusiast kajax101's Avatar
    Join Date
    Apr 2004
    Location
    London UK
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks that's intereseting.

    People allways talk about how CSS helps you easily maintain your website, and sure, it can certainly help you manage the layout and look and feel, but it's still a pain in the *** to change every one of the menu's on everyone of your pages (I suppose you can use find&replace on dreamweaver!).

    Therein lies the benefit of dynamic pages.

  4. #4
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,236
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Server-side includes are an option

  5. #5
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Atlanta, GA
    Posts
    366
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Either SSI or PHP includes are what you are looking for. There's no need to do anything with XML, not sure where you were going with that.

  6. #6
    SitePoint Enthusiast kajax101's Avatar
    Join Date
    Apr 2004
    Location
    London UK
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was thinking of an xml navigation file, with tags along the line of

    <menu>
    <submenu>

    And using perhaps ASP pages.

  7. #7
    SitePoint Wizard
    Join Date
    Jul 2004
    Location
    Minneapolis, MN
    Posts
    1,924
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could save that as a .xml document and phrase it using PHP. But the problem is that is way more work than you need. I would be easier to do something like:

    <div class="menu">
    <div class="submenu">
    </div>
    </div>

    That only requires CSS to format and in the end is easier. You can make it menu.php and include it where you want it. If you don't have PHP then use JavaScript to include it (you can do this).

    Make a menu.js and you use document.write(""); for every line (it can get annoying, but a good option for no PHP). Then use a script tag to include it. No PHP required 8)

  8. #8
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by charmedlover
    You could save that as a .xml document and phrase it using PHP. But the problem is that is way more work than you need. I would be easier to do something like:

    <div class="menu">
    <div class="submenu">
    </div>
    </div>

    That only requires CSS to format and in the end is easier. You can make it menu.php and include it where you want it. If you don't have PHP then use JavaScript to include it (you can do this).

    Make a menu.js and you use document.write(""); for every line (it can get annoying, but a good option for no PHP). Then use a script tag to include it. No PHP required 8)
    Also, if you dont have php, just make a nav page and use SSI (Server Side Includes):

    Code:
    <!--#include file="example.txt"-->
    <!--#include virtual="/path_to/example.txt"-->
    Here are some reference sites for SSI:


    http://tech.irt.org/articles/js166/
    http://www.webcom.com/~webcom/help/inc/include.shtml
    http://www.mattkruse.com/info/ssi/
    http://www.w3.org/Jigsaw/Doc/User/SSI.html
    http://cgi.resourceindex.com/Documen...Side_Includes/
    http://www.tdscripts.com/ssi.html
    http://www.internetter.com/ssi/index.html
    http://www.netmechanic.com/news/vol2/server_no8.htm

  9. #9
    SitePoint Enthusiast kajax101's Avatar
    Join Date
    Apr 2004
    Location
    London UK
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great info guys....charmedlover, can you show me how you'd include it using the php method? Could you include this in a regular html page or would you have to save the page (where the menu is included) as php?

  10. #10
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kajax101
    Great info guys....charmedlover, can you show me how you'd include it using the php method? Could you include this in a regular html page or would you have to save the page (where the menu is included) as php?
    Using a php include is very simple:

    PHP Code:
    <?php
    include "file.ext";
    ?>
    or

    PHP Code:
    <?php
    include ("file.ext");
    ?>
    And yes, you would have to save it as a php file.

  11. #11
    SitePoint Enthusiast kajax101's Avatar
    Join Date
    Apr 2004
    Location
    London UK
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    c1vineoflife, thanks for this.

    Say I was going to use the php approach, how would I code the menu include file? Could I code it in html? Or that that only work with the SSI approach (this seems the most approapriate method for me)?

  12. #12
    SitePoint Addict KelliShaver's Avatar
    Join Date
    Mar 2003
    Location
    Morehead, KY
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, it could be HTML. The file that contains the include function would need to be saved as .php, but the file you're actually calling for inclusion can be any ascii file.

  13. #13
    SitePoint Addict KelliShaver's Avatar
    Join Date
    Mar 2003
    Location
    Morehead, KY
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, if you wanted to do it with PHP & XML it wouldn't be that difficult.

    Just familliarize yourself with XPath so you understand the methodology behind it.

    For instance, if you had an XML file like the following:

    Code:
    <?xml version="1.0" ?>
    <menu>
        <item>
            <link>http://www.example1.com</link>
            <title>Example Link 1</title>
        </item>
        <item>
            <link>http://www.example2.com</link>
            <title>Example Link 2</title>
        </item>
        <item>
            <link>http://www.example3.com</link>
            <title>Example Link 3</title>
        </item>
    </menu>
    You could put a little PHP snipped in your page where you wanted your list of links like so:

    PHP Code:
    <?php
    $xml 
    simplexml_load_file('menu.xml');
    foreach(
    $xml->menu->item as $res) {
        
    printf('<a href="%s">%s</a><br />',
                
    $res->link,
                
    $res->title
        
    );
    }
    ?>
    %s is replaced by your text strings contained in $res->link and $res->title the printf() functioni replaces them in the order it gets to them.

  14. #14
    Geek of all trades ... GORF's Avatar
    Join Date
    Oct 2004
    Location
    New England
    Posts
    194
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I code for osCommerce a lot - PHP & MySQL database.
    It uses a css for the site's basic look and was a pain to redo all the time.
    I developed a backend (using osCommerce's admin interface) to store all of the css entries in a database table THEN, using PHP, write a new css (text) file on the server.

    You can see a demo here:
    http://demo.tonsofstores.com/

    And play with the admin here:
    http://demo.tonsofstores.com/admin/stylesheet.php
    http://www.tonsofwebsites.com Hosting Tons of Websites for years
    http://www.cpanelbuys.com Buying cPanel hosting companies
    http://www.namesvibe.com Cheap domains - Good vibes!

  15. #15
    Non-Member c1vineoflife's Avatar
    Join Date
    Sep 2004
    Location
    CA
    Posts
    460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KelliShaver
    Actually, if you wanted to do it with PHP & XML it wouldn't be that difficult.

    Just familliarize yourself with XPath so you understand the methodology behind it.

    For instance, if you had an XML file like the following:

    Code:
    <?xml version="1.0" ?>
    <menu>
        <item>
            <link>http://www.example1.com</link>
            <title>Example Link 1</title>
        </item>
        <item>
            <link>http://www.example2.com</link>
            <title>Example Link 2</title>
        </item>
        <item>
            <link>http://www.example3.com</link>
            <title>Example Link 3</title>
        </item>
    </menu>
    You could put a little PHP snipped in your page where you wanted your list of links like so:

    PHP Code:
    <?php
    $xml 
    simplexml_load_file('menu.xml');
    foreach(
    $xml->menu->item as $res) {
        
    printf('<a href="%s">%s</a><br />',
                
    $res->link,
                
    $res->title
        
    );
    }
    ?>
    %s is replaced by your text strings contained in $res->link and $res->title the printf() functioni replaces them in the order it gets to them.
    I tried this and nothing shows up

  16. #16
    SitePoint Addict KelliShaver's Avatar
    Join Date
    Mar 2003
    Location
    Morehead, KY
    Posts
    308
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woops, should be this:

    PHP Code:
    foreach($xml->item as $res
    Sorry.

  17. #17
    SitePoint Enthusiast kajax101's Avatar
    Join Date
    Apr 2004
    Location
    London UK
    Posts
    44
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KelliShaver
    Woops, should be this:

    PHP Code:
    foreach($xml->item as $res
    Sorry.

    Thanks for the information...I'm wading through the information links you sent (XPATH).

  18. #18
    SitePoint Addict Duilen's Avatar
    Join Date
    Jun 2004
    Location
    Mountain View
    Posts
    254
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I recently converted one of my sites from HTML to PHP. I took every element of the layout and stored it into a seperate PHP file. (menu, right sidebar, left sidebar, header, footer) The only thing I didnt store this way is the content of each individual page.
    Now instead of editing 50 pages whenever I want to change an element all I have to do is edit 1 PHP file. This has also reduced my average page size by about 50%.

    The best part about this is you really don't need to know PHP. If this is what you are trying to do follow these simple instructions.

    1. Save all html files as php files. (index.html >> index.php)
    2. Make sure your internal links point to your new php files instead of the old html files.
    3. Copy the code from any page element you would like to make dynamic. Paste that into a blank notepad and save it as a php file.
    4. Cut the code code out of your pages and replace it with this.
    Code:
    <?php
    include 'element.php';
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •