To get it out of the way, I am learning php as I go and I am new to it. I am really trying to get my hands dirty in it on this project to learn and to make my life easier!
I have a scenario, and I would love for someone to help me out through it and point me in the right direction.
My scenario is:
I have a latest news page on my 'static' website.
I am using php includes on the header, navbar and footer for every page.
I am using includes to grab the latest news information I have in assets/news/form/news1.php. This is the following:
<?php
if (!defined("ACCESS"))
{
die ("Don't waste your time trying to access this file!! Please head to the families relief home page and donate!!");
}
?>
<?php
$header = 'Article Header';
$date = 'June 1st 2013';
$url = '/news/articleName';
$body = 'Body in HTML';
?>
I then have another file in assets/news/news1.php containing:
<div id="appeal3" class="row-fluid">
<div class="well span12">
<div class="span3">
<div class="thumbnail">
<a href="<?php echo $url ?>"><img src="/img/news-blank.jpg"></a>
</div>
</div><!-- span3 -->
<div class="span9 appeals">
<p class="app-date"><?php echo $date?></p>
<a href="<?php echo $url ?>"><h3><?php echo $header ?></h3></a>
<p><?php echo substr($body, 0, 200) ?><span class="readmore"><a href="<?php echo $url ?> "> ...Read More ></a></span></p>
</div><!-- span9 -->
</div><!-- well span12 -->
</div><!-- appeal# -->
I then use the following code on my news overview page at /news/index.php to display the html with the variables entered:
<?php include("$_SERVER[DOCUMENT_ROOT]/assets/news/news1.php"); ?>
So what this gives me is an overview page, with the news article displayed around a wrapper in overview view.
I then have another page when the overview 'read more' is clicked.
Within this page, I have a full view news article page with a wrapper where I can echo the variables in.
Wha La! That is my news article structure.. Long winded isn't it!
Now, what I want!! I want to be able to include the variables from an article into my overview page and include the 2nd block of code above as the template. I then want the articles to fill out the variables. However, I have 5 articles on this page with identical variables. What is the best and most efficient way to do this??
Secondly, I have a full-view article page. How can I use this page as a template, and change the php it gets it's variables from. But, I don't want to create a new php page every time I have a new article.
What I had in mind, is something like the following:
domain.com/news/article/index.php?news1
I have been reading up on passing variables in a URL. I want to expand my knowledge on this. Could this be the solution to my problem. My issue is that I have NO idea how to go about this? Can someone please lecture me to solve this and hopefully teach me a little in between!
Thanks!