SitePoint Sponsor

User Tag List

Page 1 of 3 123 LastLast
Results 1 to 25 of 56
  1. #1
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Help with managing dynamic content

    I am building a website that will have tons and tons of content. (e.g. NY Times, CNN, Yahoo, etc.)

    I've got a couple of pretty good templates to work with, however, everything is static because it is hard-coded in HTML/CSS.

    My home page is a 3-column layout with the left and right columns fixed-width, and the middle column "fluid". And most other pages will be a 2-column layout with the right column being fixed-width, and the main column being "fluid".

    I would like to find an easy way to change the content of the middle content, and I believe PHP is the way to do this, but I'm very very rusty on PHP. (Started studying it in the past, but haven't cracked a book in ages!)

    I'm probably not ready for anything fancy like using a database, but just want an easy way to swap in and out 15-20 articles in the templates mentioned above.

    Can someone help me to better understand how I go from a "static" website to a "dynamic" website?

    Thanks,



    Debbie

  2. #2
    SitePoint Zealot Zurev's Avatar
    Join Date
    Feb 2009
    Posts
    171
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Honestly a database isn't as complicated as you think, and for what you're looking to do it would make it A LOT easier. If you're dealing with a website with as much content as comparable to nytimes like you say, you'll want to do something other than having static HTML pages.

    Have you looked into content management systems? Drupal, Joomla, Wordpress (though technically considered a blogging platform can be easily modified to your needs). They use databases, but have an administration panel, so it's a one time setup from then you can add articles in an easy to use WYSIWYG editor.

    All in all, if it as simple as using your templates, I would just setup a very simple database, and a back-end where you could put the text of an article into a new record. It would simplify things immensely.

  3. #3
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Zurev View Post
    Honestly a database isn't as complicated as you think, and for what you're looking to do it would make it A LOT easier.
    I would consider using a database if it isn't a lot of extra work, but my #1 priority s getting my site up. (I can always add in database functionality if and when my business takes off.)


    If you're dealing with a website with as much content as comparable to nytimes like you say, you'll want to do something other than having static HTML pages.
    That is why I made this thread!


    Have you looked into content management systems? Drupal, Joomla, Wordpress (though technically considered a blogging platform can be easily modified to your needs). They use databases, but have an administration panel, so it's a one time setup from then you can add articles in an easy to use WYSIWYG editor.
    Thanks, but totally not interested.


    All in all, if it as simple as using your templates, I would just setup a very simple database, and a back-end where you could put the text of an article into a new record. It would simplify things immensely.
    Okay, but let's focus on my original question first...

    What I have:
    I have a template page ("layout_2col.html") that has a Header, Middle Column, Right Column, and Footer.

    Any content (e.g. an article) is currently hard-coded into the HTML. So if I have 15 articles, I would need 15 pages?!

    Yet, ironically, the Header, Right Column, and Footer will not change.


    What I want:
    When a user selects an Item (or Sub-Item) from my drop-down Top Menu, I want that middle column to populate with an appropriate article/page.

    For instance, you choose Business>>Small Business from the Top Menu, then I'd like the middle column to load with my "Small Business landing page". (The Header, Right Column, and Footer remain the same.)

    Then lets say you are on my "Small Business landing page", and you see a link to the article "The Entrepreneur Whiz-Kid Myth" and click on it. Then I would like the middle column to load with the business article "The Entrepreneur Whiz-Kid Myth". (Again, the Header, Right Column, and Footer remain the same.)

    Next, you go back to the Top Menu (or possibly click on some other link) to read the article "Employees from Hell!!!" Again, the middle column should load the appropriate article, this time being "Employees from Hell!!!". (The Header, Right Column, and Footer always remaining the same. Thus why I call it a "template"!)

    Follow me?

    This is pretty much how any interactive website works - including SitePoint - but I just don't have a good handle of how to do that with PHP.

    (If you can help me figure out how to dissect my HTML pages and do this with "includes" or whatever, then maybe as I get more comfortable, I can look into pulling information from a database.)

    Am I making any sense?

    Thanks,


    Debbie

  4. #4
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,835
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    I have just modified a page that I wrote for another thread. The other thread just had a single page with header, left margin, middle content, right margin and footer.

    I included five extra "middle content articles" which you can check out here:

    Green Forest Resort

    The page displays different content but the images are distorted and require the dimensions setting correctly.

    <snip />
    Last edited by mizwizzy; Mar 20, 2011 at 08:30. Reason: canvassing is not permitted
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  5. #5
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Anyone else?


    Debbie

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Here's a pretty lightweight way of having reusable elements to a page, but not the only way; you could just simply use 'includes'.

    index.php
    PHP Code:
    <?php
    error_reporting
    (-1);
    ini_set('display_errors'true);
    require_once 
    'lib/Template.php';

    #base template
    $page = new Template('lib/views/page.tpl');
    $page->bind('title''Our Gallery');

    #create a header
    $header = new Template('lib/views/page.header.tpl');

    #create the content
    $content = new Template('lib/views/page.content.tpl');
    $content->bind('name''Gallery');

    #create the footer
    $footer = new Template('lib/views/page.footer.tpl');

    #assign the header, content and footer to the base template
    $page->bind('header'$header);
    $page->bind('content'$content);
    $page->bind('footer'$footer);

    #display it
    echo $page;
    lib/Template.php
    PHP Code:
    <?php
    class Template
    {
      protected
        
    $file;

      protected
        
    $data = array();

      public function 
    __construct($file){
        
    $this->file $file;
      }

      public function 
    bind($key$value){
        
    $this->data[$key] = $value;
        return 
    $this;
      }

      public function 
    render(){
        
    ob_start();
        
    extract($this->data);
        include 
    $this->file;
        return 
    ob_get_clean();
      }

      public function 
    __toString(){
        return 
    $this->render();
      }
    }
    lib/views/page.tpl
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssbase/base-min.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssfonts/fonts-min.css" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
        <title>
          <?php echo $title?>
        </title>
      </head>
      <body>
        <div id="site-container">
          <?php echo $header?>
          <?php echo $content?>
          <?php echo $footer?>
        </div>
      </body>
    </html>
    lib/views/page.header.tpl
    PHP Code:
    <div id="site-header">
      
    Header
    </div
    lib/views/page.content.tpl
    PHP Code:
    <div id="site-content">
      <h1>
        This is the <?php echo $name?> page.
      </h1>
    </div>
    lib/views/page.footer.tpl
    PHP Code:
    <div id="site-footer">
      
    Footer
    </div
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply, Anthony, but I think using object-oriented programming is a bit much for me.

    It would help to just talk out what I'm trying to do and get some suggestions on "a better mouse-trap" if you follow?!

    There is definitely a need for a dialogue here!

    Thanks,


    Debbie

  8. #8
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    If anyone is interested and wants to help, I can take the time to explain what I trying to do and where I'm confused...


    Debbie

  9. #9
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,835
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by DoubleDee View Post
    If anyone is interested and wants to help, I can take the time to explain what I trying to do and where I'm confused...


    Debbie
    If you supply the ("layout_2col.html") I am sure that with the additional information someone with spare time on their hands will produce what you want.

    Without further information I don't think anyone's guesses will be getting any warmer
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  10. #10
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    If you supply the ("layout_2col.html") I am sure that with the additional information someone with spare time on their hands will produce what you want.

    Without further information I don't think anyone's guesses will be getting any warmer
    I can post a sample online after supper...


    Debbie

  11. #11
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    If you supply the ("layout_2col.html") I am sure that with the additional information someone with spare time on their hands will produce what you want.

    Without further information I don't think anyone's guesses will be getting any warmer
    Feeling really exhausted tonight.


    Okay, so here is a URL to a simple mock-up...

    Debbie's Test Site

    So let's you go to the menu and choose Business>>Jobs, then I'd like to have a "sub-page" dynamically loaded in the Middle Column.

    After that, maybe you'd choose, Business>>Markets and a page with Stock Market Reports would appear in the Middle Column.

    The goal is to avoid having to hard-code one page that is my 3-column layout PLUS "Job Listings" in the middle column. And then having to hard-code another 3-column layout PLUS "Stock Market Reports" in the middle column and so on.

    Of course my website will be more complex than this, but I figure this is a good drill.

    Hope that makes sense?!



    Debbie

  12. #12
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,835
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Last edited by spikeZ; Mar 23, 2011 at 09:46.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  13. #13
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi John, I'm pretty sure that's not what Debbie is looking for.

    Debbie, take a read over this and let me know if you have any questions.

    index.php
    PHP Code:
    <?php
    error_reporting
    (-1);
    ini_set('display_errors'true);

    function 
    render($file){
      if(
    is_readable($file)){
        return 
    file_get_contents($file);
      }
      return 
    '';
    }

    $pages = array(
      
    'default'   => 'home.tpl',
      
    'about-us'  => 'about-us.tpl'
    );

    $content $pages['default'];

    if(!empty(
    $_GET['page']) && array_key_exists($_GET['page'], $pages)){
      
    $content $_GET['page'];
    }

    include 
    'lib/views/page.tpl' ;
    lib/views/page.tpl
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssreset/reset-min.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssbase/base-min.css" />
        <link rel="stylesheet" type="text/css" media="screen" href="http://yui.yahooapis.com/3.3.0/build/cssfonts/fonts-min.css" />
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
        <title>
          Demo
        </title>
      </head>
      <body>
        <div id="site-container">
          
          <div id="site-header">
            <?php echo render('lib/views/page.header.tpl'); ?>
          </div>
          
          <div id="site-content">
            <?php echo render('lib/content/' $content); ?>
          </div>
          
          <div id="site-footer">
            <?php echo render('lib/views/page.footer.tpl'); ?>
          </div>
          
        </div>
      </body>
    </html>
    lib/views/page.header.tpl
    PHP Code:
    Header 
    lib/views/page.footer.tpl
    PHP Code:
    Footer 
    lib/content/home.tpl
    PHP Code:
    <h1>
      
    Welcome to our site!
    </
    h1
    You would access the unique content using the following syntax in the URL:-

    index.php?page=default
    index.php?page=about-us
    Last edited by spikeZ; Mar 22, 2011 at 14:29.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  14. #14
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,835
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Originally Posted by John_Betong
    Here we go:

    Hi John, I'm pretty sure that's not what Debbie is looking for.
    Hi Anthony,

    Did you try the link and any of the drop-down menu items?

    I split Debbie's script and included separate top menu, left, right middle and footer sections.

    The middle section has a default and checks for a $_GET page parameter. If a page parameter is passed from the exiting menu then a different thumbnail is shown otherwise a default thumbnail is shown.

    The code I used is very similar to the scripts you supplied.
    Last edited by spikeZ; Mar 22, 2011 at 14:29.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  15. #15
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    Hi Anthony,

    Did you try the link and any of the drop-down menu items?
    I'd like to know, John, why your code has this in it...

    ../../../subdomain/thumb/before-i-screw-you-are-you-over-18-cutie-pie_thumb.jpg
    If you're trying to "screw me over" then you came to the wrong place!

    (I also didn't appreciate the picture of a topless woman in your code!)

    Welcome to my Ignore List!


    Debbie

  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    yes John, please sort out (remove) the rotating ads and the dodgy pictures and I will let the link stay.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,835
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by spikeZ View Post
    yes John, please sort out (remove) the rotating ads and the dodgy pictures and I will let the link stay.
    No offence intended.

    Changes made as requested.

    To demonstrate page changes the first 50 thumbnail JPGs were selected from an existing path and without checking, numerically hard-coded a default image.

    Lesson learnt to check all eventualities.







    .
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  18. #18
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Changing content (but not page) with PHP

    I have a simple page with a Top Menu. I would like to have the content below it change, but not the page.

    In other words, I want to swap out the content below, but keep the same page.

    Thanks,


    Debbie

  19. #19
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You need to use JavaScript for such a thing.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  20. #20
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    You need to use JavaScript for such a thing.
    Wrong!

    And, ahem, you're in a PHP forum. (No JavaScript!)


    Debbie

  21. #21
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    ...

    Am I going have to explain why you cannot do this with PHP?
    Some how did all my years of working with PHP become null and void?
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  22. #22
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    ...
    Am I going have to explain why you cannot do this with PHP?
    Some how did all my years of working with PHP become null and void?
    Pretend I am on index.php and it has a white background with two buttons: Red, Blue

    The user clicks on Red, and PHP serves up the same index.php file with the same two buttons, but this time a red background.

    The user next clicks on Blue, and PHP serves up the same index.php file with the same two buttons, but this time a blue background.

    Please explain where JavaScript is coming into this...


    Debbie

  23. #23
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    To do it without changing the URL (example.tld/index.php) would be impossible with PHP. Unless the buttons in question are part of a form, which then the result is stored in a session or cookie. Otherwise a query string must be appended to the URL. To change content on a page without changing the page itself, ie., changing the URL requires JavaScript.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  24. #24
    SitePoint Wizard DoubleDee's Avatar
    Join Date
    Aug 2010
    Location
    Arizona
    Posts
    3,777
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    To do it without changing the URL (example.tld/index.php) would be impossible with PHP. Unless the buttons in question are part of a form, which then the result is stored in a session or cookie. Otherwise a query string must be appended to the URL. To change content on a page without changing the page itself, ie., changing the URL requires JavaScript.
    Okay, let's step back and take a look at a real-life example (that still won't ever use JavaScript)...

    Image a webpage called "index.php" that has a horizontal Top Menu and nothing else. Naked. Blank. White.

    The top menu has these categories:

    Home | News | Business | Sports | Weather | Opinion

    When the user clicks on an category - except "Home" - a drop-down menu appears with a series of choices.

    For example, under "Business" there might be:

    - Job Listing
    - Today's Stock Market
    - Contact Better Business Bureau
    - Contact Chamber of Commerce
    - Business Tips
    - This Day in History

    Each of those above choices would have a body of text/information.

    In a super simple website, each might represent a separate page, HOWEVER, I want all of that content to appear on my "index.php" page.

    Why?

    The fixation isn't on "index.php", but on the fact that I want the page's template (e.g. color, styles, Top Menu) to be on each page, and instead of building 20 pages with redundant design, I want ONE DESIGN/TEMPLATE with content that is swapped in and out depending on what the user selects!!

    (No databases for now, please!)

    What I am trying to do is your basic "dynamic PHP website".

    If the base URL (i.e. "index.php") needs to be appended with some query string as you alluded to, then that is fine. But what I do not want is this...

    index.php ---->Article1.php
    index.php ---->Article2.php
    index.php ---->Article3.php
    index.php ---->Article4.php


    Another important concept...

    I have seen lots of examples where people cut up the Template and include it in a file with the content.

    That seems really strange.

    In my mind, the Template should be STATIONARY and the Content should be SWAPPED IN AND OUT. (Not the other way around?!)

    Does that help explain what I am trying to learn?



    Debbie

  25. #25
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,027
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Have you considered having the template as a php file which is basically all HTML with things like user names, page content, page headings, page titles etc echo'd in. Your scripts would generate the various parts and copy them into variables. The template would be included at the end with a number of for example:

    PHP Code:
    <h1><?php echo $main_heading?></h1>
    You would need to have a controlling script(s) which would generate/load the relevant script(s). No javascript needed.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator


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
  •