Results 1 to 10 of 10

Thread: Non-database 'CMS' written in PHP

  1. #1
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Post Non-database 'CMS' written in PHP

    I've been toying with the idea of a sort-of-cms website that uses a single universal newsarticle.php page that is blank if you solely open that file; but has a php script (where you want the news article to appear) that retrieves a variable from the window.location.href passed on from the previous page

    Code:
    <?php
    ######################################
    # This is where the problem is, somehow retrieving the number "23"
    # from the address bar so that it knows which XML file to parse.
    # I know that the below function is completely wrong though in regards
    # to variable retrieval, but I'am still new to PHP :P
    ######################################
    if (!$myxml=simplexml_load_file('window.location.href')){
    
            echo 'Error reading the XML file';
    
            }
    
            foreach($myxml as $article){
    
                    echo '<h3> ' . $article->title . '</h3>';      
                    echo '<a href=','' . $article->sourcelink . '','>' . $article->sourcelink . ' | ' . $article->date . '</a><br />';  
                    echo '' . $article->story . '';
    
            }
    
    ?>
    ie:
    http://mysite.com/index.php has a link that goes to
    http://mysite.com/newsarticle.php?id=23

    the variable being 23 in which the aforementioned PHP coded into newsarticle.php then parses and displays, say, 23.xml, which could be coded something like this:
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
       <index>
          <article>
             <title>Alien from mars speaks his/her mind at UN conference</title>
             <source>BBC World News</source>
             <date>12/25/08</date>
             <sourcelink>http://bbc.co.uk/world/5674alien.aspx</sourcelink>
             <story>blah blah blah blah</story>
          </article>
       </index>
    Likewise if the variable had been http://mysite.com/newsarticle.php?id=24, then 24.xml would have been parsed instead.

    Thoughts?
    Last edited by Spinethetic; 05-03-2008 at 10:49 PM. Reason: adding in commented PHP code

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    it seems like to many xml files, what if you had 100 stories? 100 xml files seems unreasonable.
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. #3
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    PROBLEM SOLVED!

    Man I'am really starting to love PHP! I don't know why I diden't switch before!

    Code:
    <?php
    $variable = $_GET['id'];
    
    if (!$myxml=simplexml_load_file(''.$variable.'.xml')){
    
            echo 'Error reading the XML file';
    
    }
    ### Rest of code irrelevant ###
    mysite.com/view.php?id=abcdefg will load and parse abcdefg.xml, just as easily as mysite.com/view.php?id=h65h3456h56jkedj will load and parse h65h3456h56jkedj.xml, as long as the files exist anyway.

    Best Regards
    ~Ross

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Just a tip.
    You can change:
    Code:
    if (!$myxml=simplexml_load_file(''.$variable.'.xml')){
    To this:
    Code:
    if (!$myxml=simplexml_load_file($variable.'.xml')){
    Jeremy | jfein.net

  5. #5
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by Nile View Post
    Just a tip.
    You can change:
    Code:
    if (!$myxml=simplexml_load_file(''.$variable.'.xml')){
    To this:
    Code:
    if (!$myxml=simplexml_load_file($variable.'.xml')){
    I am new to php, so I must ask, what is the functional difference? I've gotten to chapter 5 in a book that I purchased and we havent really gotten tat far, (at least I think)

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Its just cleaner.
    When you start your code with a variable, lets call it $var, instead of:
    PHP Code:
    echo ''.$var.' is the value of the variable.'
    You might wanna just do this:
    PHP Code:
    echo $var.' is the value of the variable.'
    Then say, you wanna end with a variable, instead of doing this:
    PHP Code:
    echo 'This is the value of the variable: '.$var
    But then say your using double quotes("). Then you don't even need to include the concatenation, and double quotes.
    So, it'd be something like this:
    PHP Code:
    echo "$var is the value of the variable"
    Jeremy | jfein.net

  7. The Following User Says Thank You to Nile For This Useful Post:

    Spinethetic (05-04-2008)

  8. #7
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Ahh, I see.

    I still have a couple specific, but small problems with using this whole setup on my site. How do I return the article title itself to parse between <title></title> in the basic HTML; In the script I have ' . $article->title . ' which displays the article title from XML <title>The Last Question</title>. I really don't want a generic page title that is the same across every news article.

    And I also have <subtitle>seconday title text</subtitle> that I will only be using on a few articles. There must be a way that I could go like so: <subtitle active="false"></subtitle> and the PHP will then ignore the line I have in bold so that I don't have an unnecessary line of whitespace:
    Code:
    <?php
    $variable = $_GET['id'];
    
    if (!$myxml=simplexml_load_file($variable.'.xml')){
    
            echo 'Error reading the XML file';
    
            }
    
            foreach($myxml as $article){
    
                    echo '<h2> ' . $article->title . '<span></span></h2>';      
                    echo '<b>' . $article->subtitle . '</b><br />';  
                    echo '<a href=','' . $article->link . '','>' . $article->source . ' | ' . $article->publishdate . '</a><br />';
                    echo '' . $article->content . '';  
                    echo '<p class=','meta','> <span class=','posted','>Posted by <a href=','mailto:admin@integralbuddha.net','>Ross Vaughn</a> on ' . $article->publishdate . '</span> <a href=','' . $article->permalink . '',' class=','permalink','>Permalink</a></p>';
    
            }
    
    ?>
    This is the link I'am testing the script on http://www.integralbuddha.net/n/v.htm?id=2
    Last edited by Spinethetic; 05-04-2008 at 10:37 PM. Reason: added link for clarification

  9. #8
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    I didn't read your 2nd question, but I'm guessing that it also has to do with combining HTML and PHP like the first, so all you'd do is replace the:
    HTML Code:
    <title>The Last Question</title>
    With this:
    PHP Code:
    <?php
    echo "<title>The Last Question - $article->title</title>";
    ?>
    Jeremy | jfein.net

  10. The Following User Says Thank You to Nile For This Useful Post:

    Spinethetic (05-04-2008)

  11. #9
    Join Date
    Aug 2005
    Posts
    115
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default

    Hmm, I should've been able to figure that one out on my own, I guess I was just getting caught up in the moment while I'am brooding over this technical scripting, (at least to me =P) and dident think.

  12. #10
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Alright, glad to help you.
    Jeremy | jfein.net

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
  •