ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm doing a website for somebody. One of the pages contains news. The most recent news should be at the top of the page. As there are a lot of news entries (one entry per month over the last 4 years), the page would be extremely long so it's better to split it into a few pages (news.html, news1.html, etc.) The problem is that if I need to update it with new info (which would go at the top, I'd have to update all the pages as well, which makes it a very inefficient solution.
How would I go about solving this problem? I'm sure there's some solutions. Perhaps PHP or jquery?
I'd appreciate pointing me in the right direction.
I would use PHP and MySQL pull the news items from a database ordering chronologically.
You can limit the number news stories on each page using LIMIT and add a next link to pull down the next n queries to fill the page.
But it's just one of the subpages. Would it make sense to install a content management system just for that?
---------- Post added 05-29-11 at 02:12 PM ----------
Quote:
Originally Posted by hyperhead
I would use PHP and MySQL pull the news items from a database ordering chronologically.
You can limit the number of queries and add a next link to pull down the next n queries to fill the page.
You would need:
One input form
One Edit form
1 MySQL database.
That would do it.
Sorry, could you elaborate on it? I'm a beginner when it comes to PHP.
Yes, of course it would. You would use the CMS to build the rest of the site too.
The problem is that I spent a lot of time creating this website from scratch (html/css/jquery). I wouldn't want to
just throw it away and start with CMS.
One more question: how would I initially (and at a later time) populate the database?
Excellent question. The answer is that you would have to create forms into which website content could entered. You would also have to create form handlers (in PHP, or in whichever language you are using for the backend) to transfer the data from the posted forms into the database. And you would have to design and build a database to support the functionality you need. Once you've designed and built all this, you've already written a CMS.
Now, I'd like to go back to an earlier point you made:
Quote:
Originally Posted by portia
But it's just one of the subpages. Would it make sense to install a content management system just for that?
I'm going to turn this around. Why would it not be worth it to install a CMS just for that?
If you want to use Wordpress for the rest of your site and not just news, you would have to convert your existing work into a Wordpress theme (and, probably, the Javascript into Wordpress plugins). This is not trivial, but it's not as hard as it sounds. For example, you can keep all of your existing CSS. Your jQuery files would work the same way (and most likely would just need to be repackaged). You just need to write the PHP in the theme to generate the HTML that you have in your current site. It's not any more difficult than the alternative that has been proposed, and it's much more likely to be consistent with database design and security best practices (because those are taken care of for you).
There would be the need for a bit of scripting to get the initial data into the database.
Would basically have to wrap SQL syntax around the content and insert in.
Could be done via MySQL client (do you have SSH access to webserver??) or perhaps PHPMyAdmin if it was installed Then it would be a case of cutting and pasting the inserts or uploading a text file.
Alternatively Im sure a PHP script to upload a whole file of inserts could be found.
The most recent news should be at the top of the page. As there are a lot of news entries (one entry per month over the last 4 years), the page would be extremely long so it's better to split it into a few pages (news.html, news1.html, etc.)
The best solution depends on what you already use, and how you maintain the news content.
One possibility often overlooked is to keep each news entry (the HTML code) in a separate file, with the file name being the search key, with all news files in a dedicated directory. Then you can use a scripting language to pull the HTML news fragment(s) into the page content.
If you want to use client-side Javascript, you can use for example a hidden iframe to load news fragment files, then using DHTML to copy the content HTML to the news pane. This lets you format the news HTML as a complete page, while only using some element of it for the actual display.
If you display news monthly, I recommend you name the HTML news entry files YYYY-M-I.html, where YYYY is the year (2011), M is the month (0 to 11), and I is the index, 1 for the first entry of each month, 2 for a second entry in the same month, and so on; and put them in a dedicated directory. That way you can use the Date object to easily construct the URLs for each news entry. To get the data for each month, start at index 1. If the load succeeds, save the data, and try index 2. If that too succeeds, prepend that to the saved data (so newer news are displayed first), and try the next index, until the load fails. Then, you have the complete data for that month.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.