Jump to content

PHP Blog Function


jmhyer123

Recommended Posts

Just a quick question...

I am working with a free script i got and modified to suit my blogging needs. I only have one problem. Does anybody know of a script/snippet to make it so my post only goes so long and then says "Read More..." and has a link to the whole post instead of just displaying the whole post on the homepage? I just need a quick snippet that works and then I can modify it to suit my needs. It just needs to make it automatically say "Read More..." and have a link to the whole article.

Thanks in advance...

jmhyer123
Link to comment
Share on other sites

There is no magical function to do this. You can use [url=http://php.net/substr]substr[/url] to truncate your topics, but you will then need to make a script to display the whole article. Then you would simply make a link to said script, passing it the articles id through the url.
Link to comment
Share on other sites

[code]<?php

$string = '<p>massive <a href="here">long</a> piece of <strong>text</string> that is never gonna fit<p>';

$strarr = explode(' ', strip_tags($string));

$max = 40;

$max_words = count($strarr) > $max ? $max : count($strarr);

$newstr = NULL;
for ($i = 0; $i < $max_words; $i++)
{
$newstr .= $strarr[$i] . " ";
}

echo "<p>" . $newstr . "</p>";

?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.