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
https://forums.phpfreaks.com/topic/33536-php-blog-function/
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
https://forums.phpfreaks.com/topic/33536-php-blog-function/#findComment-156989
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
https://forums.phpfreaks.com/topic/33536-php-blog-function/#findComment-156992
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.