Help - Search - Members - Calendar
Full Version: [resolved] Build a Blog Features
Codegrrl.com Forums > Script Help > Tutorial Help
tjs
I have 2 features that I would like to have on my blog, but don't know how to add them:

1. I want to limit the number of characters displayed for each post on the main page and a link that says, "read more" that will take the reader to the single entry page
2. A link on the main page to next 5 older posts

Thanks!
echolalia
Okay, before I say anything else: I remember seeing this in another thread and making a mental note (for possible future use). So I took a chance and gave it a whirl, hoping I could be of some assistance with your first request.

You can truncate the number of characters in your post using the substr() function. Using Jenny's example, I added the part that trims the post length after the variables:
CODE
    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $password = $row['password'];
    $id = $row['id'];

if (strlen($entry) > 90)
{
$entry = substr($entry,0,90);
$entry = "$entry... <br /><br /><a href=\"journal.php?id=" . $id . "\">read more</a>";
}

Basically, the code is saying if the string length of the entry is more than 90 characters, only display the first 90 characters, followed by "..." and a link to the single entry page.
Of course you can set whatever number you like (90 is pretty small) and format the link however you please.
In the post I linked to, there's an example of how to cut off after a certain number of words, but I haven't tried it.

I hope this helps! If it goes all wonky instead, I'm positive someone with more knowledge than I will chime in to help us out
loadx
next 5 older posts youll need a date
tjs
QUOTE(echolalia @ Feb 16 2007, 10:38 AM) *

Okay, before I say anything else: I remember seeing this in another thread and making a mental note (for possible future use). So I took a chance and gave it a whirl, hoping I could be of some assistance with your first request.

You can truncate the number of characters in your post using the substr() function. Using Jenny's example, I added the part that trims the post length after the variables:
CODE
    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $password = $row['password'];
    $id = $row['id'];

if (strlen($entry) > 90)
{
$entry = substr($entry,0,90);
$entry = "$entry... <br /><br /><a href=\"journal.php?id=" . $id . "\">read more</a>";
}

Basically, the code is saying if the string length of the entry is more than 90 characters, only display the first 90 characters, followed by "..." and a link to the single entry page.
Of course you can set whatever number you like (90 is pretty small) and format the link however you please.
In the post I linked to, there's an example of how to cut off after a certain number of words, but I haven't tried it.

I hope this helps! If it goes all wonky instead, I'm positive someone with more knowledge than I will chime in to help us out


Hey that did exactly what I wanted! Thanks a lot!
If anyone can help me out with the code to the next 5 older entries, I would appreciate it!
Thanks
Steven
Where would that code go, echolalia?
tjs
QUOTE(Steven @ Feb 19 2007, 05:19 AM) *

Where would that code go, echolalia?


Steven,
Open up the main page of your blog, find the following code:
CODE
    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $password = $row['password'];
    $id = $row['id'];


And beneath that paste this code:
CODE
if (strlen($entry) > 90)
{
$entry = substr($entry,0,90);
$entry = "$entry... <br /><br /><a href=\"journal.php?id=" . $id . "\">read more</a>";
}


There you go!
btw I'm still looking for an answer to the other part of my question! wink.gif
Amelie
For the next five older posts, you will need to implement pagination. Here is just one of many tutorials on how to do it.
Steven
Thanks tjs, I'll try that!

Amelie, thanks for the link!

EDIT: I'm not quite sure how to implement that into my blog...
Amelie
I found a thread which has done it for you:

http://codegrrl.com/forums/index.php?showtopic=9544
Steven
I should have searched! Thanks Amelie!
tjs
QUOTE(Amelie @ Feb 19 2007, 08:21 PM) *

I found a thread which has done it for you:

http://codegrrl.com/forums/index.php?showtopic=9544


Wow thanks that did exactly what I wanted! clap.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.