Welcome to Webmaster Resources 101
Webmaster resources, forums, articles & tools.
Our Network:
How To Put Your Articles Into Seperate Pages
[ About This Author :: Request Reprint :: Print Article :: Tell A Friend ]
How To Put Your Articles Into Seperate Pages
By Ben Sinclair
http://www.webmaster-resources101.com
This is a cool little way to put articles from a page or database into seperate pages. This can be done quite a few ways but here's one of them. So lets get into it!
<b>The Article Part</b>
Lets say this is your (extremely short) article:
<i>Hello,
This article is about nothing much... This is just here for a page example.
I could go on forever... bla bla bla bla bla bla bla bla bla bla
And again... bla bla bla bla bla bla bla bla bla bla bla.</i>
OK, you want to "cut up" the article into 3 seperate pages so that it is displayed better and is easier to read. This is what you would add to your article. You'll need to add a little bit of PHP:
<font color="green"><?php
$pages = "3"; // How many pages you want on the page
$article = <<<EOF
Hello,
This article is about nothing much... This is just here for a page example.
{ENDPAGE1}
I could go on forever... bla bla bla bla bla bla bla bla bla bla
{ENDPAGE2}
And again... bla bla bla bla bla bla bla bla bla bla bla.
{ENDPAGE3}
EOF;
?></font>
<b>The Code</b>
Now that your article has been "cut up", you'll need this code belwo the above code:
<font color="green"><?php
// Remove this code below if you don't
// what it to add breaks (<BR>) automatically.
$article = nl2br($article);
// Make sure there are no stuff ups.
if ($pages > 1) {
if (!$page || $page <= "0") {
$page = "1";
}
$article = "{ENDPAGE0} ".$article;
$pagea = $page - 1;
$pageb = $page + 1;
// Check that the page exists
$match_count = preg_match_all("/{ENDPAGE"."$pagea"."}(.*?){ENDPAGE"."$page"."}/is", $article, $matches);
if ($match_count == "" || $match_count == "0") {
$article = "This page does not exist!";
} else {
if( preg_match( "/{ENDPAGE"."$pagea"."}(.*?){ENDPAGE"."$page"."}/is", $article, $match ) )
$article = $match[1];
}
// Generate Page Numbers
if ($page > "1") {
$prev = "<a href="$PHP_SELF?page=$pagea"><< Prev</a> :";
} else {
$prev = "<< Prev :";
}
if ($page < "$pages") {
$next = ": <a href="$PHP_SELF?page=$pageb">Next >></a>";
} else {
$next = ": Next >>";
}
for ($p=1 ;$p <=$pages ; $p++ )
{
if ($page == $p) {
$direct_bar .= "<b>$p</b> ";
} else {
$direct_bar .= "<a href="$PHP_SELF?page=$p">$p</a> ";
}
}
}
// Finish off the page
print <<<EOF
<p>$prev $direct_bar $next</p>
EOF;
print $article; // Put article onto page
print <<<EOF
<p>$prev $direct_bar $next</p>
EOF;
?></font>
And that's it! You should now have three pages instead of one. This really helps to make it all look neat. This same thing can be done with MySQL or any other database just by selecting the article out of the database.
Enjoy!
Discuss this in our Webmaster Forums
Ben Sinclair
http://www.webmaster-resources101.com
Ben Sinclair is the Webmaster of Webmaster Resources 101 and Webmaster Forums 101.
| Go To Top | This article has been read 886 times. |
[ About This Author :: Request Reprint :: Print Article :: Tell A Friend ]
Best 10 Web Hosting
Leading Web Hosting Industry Directory. Host Search, News and Reviews. Compare the Best Shared Hosting Plans Under $10 a Month. Unix, Windows and Java hosts. Budget, Shared, Reseller and Dedicated providers. Hosts in Canada, Australia and Europe.
Link Exchange
LinkAdage allows webmasters to make money on their websites buying and selling relevant, high pagerank / high traffic text links.
Web Hosting
» Web Hosting India
Software
» MAS 90
Link Popularity
» Reciprocal Link Exchange Directory