I am creating a blog and wanted to be able to have the posts show up on the homepage (which I have coded flawlessly), but I want them to be posted to another page at the same time and ad a "read more" link where they can see the full post.

I want to do this for two reasons.

1. I only allow 4 posts to show up on the homepage at a time.
2. Will help people using the search function to find all of the articles.

I don't use Blogger or Wordpress it's all hand coded. Anyone want to point me in the right direction? Thanks in advance.

Recommended Answers

All 2 Replies

Member Avatar for diafol

I assume that you have a generic 'story' page that displays the complete article. Your db table in this case will be something like (simplified):

id
user_id (poster)
title
summary (the bit that shows in the front page)
article (the complete story)

At the end of your summary, you'd have something like:

<a href="story.php?id=<?php echo $id;?>">read more...</a>

where $id would be taken from the 'id' field in the db table

However, you may find that the complete story is on another site, in which case you just need to store the url:

id
user_id (poster)
title
summary (the bit that shows in the front page)
article (the complete story)
url (external link)

You could add another field to note which field to use (article or url), but let use assume that if url is not null, then use this:

if url:

<a href="<?php echo $url;?>">read more...</a>

if article:

<a href="story.php?id=<?php echo $id;?>">read more...</a>

For the url scenario, you could add the 'target = "_blank"' attribute/value to open the external site in a new tab/window. Many frown upon this (and xhtml strict won't validate), but the choice is yours. I like links to new websites to open in new tabs, but that's just a personal preference and I'm probably in the minority by now.

Wow thanks alot.

My 'story' page is actually the index page, and the form is on the homepage as well.

My database is like this:

id
name (poster)
topic (name of post)
email (for contact purposes not displayed)
description (content of post)

I suppose that instead of description I should have summary and article.

Seems to make sense. My form has:

$sql="INSERT INTO posts (topic, name, email, description)
VALUES
('$topic','$name','$email','$description')";

How should I change this so that only a 'preview' shows up on the front page and then the rest is on the read more link? All of the article's will be stored on my site so no external links.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.