Help - Search - Members - Calendar
Full Version: News Code (kinda Like An Iframe)
Zymic Webmaster Forums > Web Design & Development > Client Side Scripting > HTML and CSS
Jacob
Well, basically what I need this for is a News/Updates section. What I would to do is make it so I can insert the code (something along the lines of src="news.php") and then put that code into my website where ever I would like the news to appear. Instead of constantly updating 40-ish files every time I have new news or updates. I do not mind whether it is in PHP or (X)HTML.

Jacob.
Banjo
Would php include work ?

CODE
<?php include("news.php"); ?>


or in Html/Javascript could do something like this

have a js file like this

CODE
document.write('This is where we have news, add as mand rows as you like');
document.write('This is where we have news, add as mand rows as you like');


and place this in the html

CODE
<script language="JavaScript" src="news.js"></script>

MrTouz
i really suggest using includes. Easy to manipulate and i do NOT know if the JS will work if users have JS off.
Andrew
Yea php includes are awesome. I also think Narzy if you spit your sites layout code in half, and put one half in a file called header.php and the other half in a file called footer.php and include both of those, it makes updating your site SOOO much easier. It's amazing.

If you need some help doing that, I can find tutorials or explain it better.
Jacob
Yea, I am going to do that. My header is going to include nav and sub nav, login (user registrations, etc.). Then the news thingy and finally the footer is going to hold all the usual stuffs.

Thanks all. Greatly appreciated.

Jacob.
Andrew
I wouldn't put the news in the header, but thats just me. I'd put it in its own seperate file called news.php then include that separately.

That way it's easier to take off one page and have it on another. And if you ever change your news script, you only have to go through the news.php file, and not all your html code for the site. But thats just me, do what you will
Jacob
Sorry Trippin7464, what I meant to say was I am making a header.php, news.php and footer.php as in separate files so that it is very simple to do. I love the php include, it makes life that much easier.
Well, [here] it is. It is my own custom design and I coded it from scratch. It is also backed by my custom CMS which makes it easy for all to use. I am looking to implement user auth (personal and business accounts), forums (possible custom made also), and a 24/7 automated response system. Some of the pages, have the news longer then the actual content but that can be fixed when I finish inputting content.

Jacob.
MrTouz
What i would suggest is a main page : index.php where you put all your codes and includes. on the main page have something like this in the specific area (middle):

CODE
<?php
if(!isset($_GET['to'])) {
    include "home.php";
}elseif(!file_exists($_GET['to'].".php")) {
    include "error.php";
}else{ //if all goes well
    include $_GET['to'].".php";
};?>


Change it to news.php if you want and your page once you go to index.php will start with news.php the link on tops will be 'index.php?id=news' and inside your news.php you can have just content.

That is what i do with my sites, which makes it easier to modify, you have ONE page that holds up all your codes and includes (index.php) and you have other pages that you add up all the time...

The code above, i heard was not the secured way before you could call files up from other paths since it was not blocked. I have a special script made for me (can't share, agreement with the one that made it) but really you can find anyone that can do the same. It kind of does many things at once and i find it better than having a header.php and a footer.php even tho load time can be fast... but that means inside each files youll have to add include 'header.php' ... at a time it pisses me of tongue.gif so i took an other code... PLUS you get the sexy index.php?id= thing smile.gif
Andrew
Mr. Touz what he did is basically the cleaner more legible way of doing it.
I personally think that index.php?id=blah looks ugly. it's okay for a php script that NEEDS multiple variables but for a professional site, I think index.php and blah.php and about.php etc looks a whole lot nicer.

And there is still only ONE page with codes in it. Well technically three in NaRzY's case, but it's still really simple.
Jacob
The aim was to keep it simple as possible. As when something happens and I get a phone call/email asking me what has happened, it makes things a whole lot easier.

Jacob.
Bogey
[here] is a basic tutorial I wrote on the subject.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.