View previous topic :: View next topic |
Author |
Message |
Benzer
Joined: 23 Jun 2002 Posts: 31
|
Posted: Mon Jul 28, 2003 7:24 pm Post subject: Turn posts into multiple pages without adding <!--more--& |
|
|
This is a hack developed in an old version of b2, v0.6pre. It may still work in the newest version since it does not use any b2 functions.
This hack allows the user to cut a single post into multiple pages without worrying about adding a <!--more --> tag, thus making it very easy to shift from single to multiple page mode. It is actually a modification to the_content() function, which is called within the b2 loop, and designed to be used in single post mode.
In the b2template.functions.php file, replace this function:
Code: | function the_content($more_link_text="(more...)",$stripteaser="0",$more_file="") {
$content = get_the_content($more_link_text,$stripteaser,$more_file);
$content = convert_chars($content,"html");
echo $content;
} |
by this function:
Code: | function the_content($more_link_text="(more...)",$stripteaser="0",$more_file="", $AB_choose_p_or_w, $AB_words) {
$content = get_the_content2($more_link_text,$stripteaser,$more_file, $AB_choose_p_or_w, $AB_words); //modified line
$content = convert_chars($content,"html");
$content = stripslashes($content); //new line
echo $content;
} |
Then, add this new function somewhere at the end of the file before the ?> tag:
Code: | function get_the_content2($more_link_text="(more...)",$stripteaser="0",$more_file="", $AB_choose="words", $AB_words=380) {
global $AB_start,$AB_page,$id,$postdata,$more,$c,$withcomments,$page,$pages,$multipage,$numpages;
$output = "";
if (($c) || ($withcomments))
$more="1";
if ($more_file != "") {
$file=$more_file;
} else {
$file=$PHP_SELF;
}
#$AB_choose = "paragraph"; //can be "words" or "paragraph"
if ($AB_choose == "words") {
$content = explode(" " , $postdata["Content"]);
}
else {
$content = explode("<br />\n<br />" , $postdata["Content"]);
}
if (!isset($AB_start)) {$AB_start = 0;}
if (!isset($AB_page)) {$AB_page = 0;}
$total_words = count($content);
$end_words = 0;
if ($AB_words == "all") { $end_words = $total_words;}
else {$end_words = $AB_words + $AB_start;}
if ($end_words > $total_words) {$end_words = $total_words;}
$n_pages = intval($total_words / $AB_words) + 1; // plus one because its a math floor operation
if ($AB_page > 0) {
if ($AB_choose == "words") {$output .= "... ";}
else {$output .= ">>> ";}
}
if ($AB_choose == "words") {
for ($i=$AB_start; $i<$end_words; $i++) {
$output .= $content[$i]." ";
}
} else {
for ($i=$AB_start; $i<$end_words; $i++) {
$output .= $content[$i]."<br /><br />";
}
}
if ($AB_page < $n_pages - 1) {
if ($AB_choose == "words") {$output .= " ...";}
else {$output .= " >>>";}
}
$output .= "<br /><br />\n";
if ($n_pages > 1) {
for ($i=0; $i<$n_pages; $i++) {
$output .= "<a href=\"$file?p=$id&AB_start=".($AB_words*$i)."&AB_page=$i\">";
if ($i == $AB_page) { $output .= "<font color=\"black\"><b>[ ".($i+1)." ]</b></font></a> ";}
else { $output .= "[ ".($i+1)." ]</a> ";}
}
}
return($output);
} |
Then, call this function from your blog page:
Code: | <?php the_content("","","","paragraph", 3); ?> |
Parameters: the 3 first parameters (for simplicity) are the same as the old the_content() function; last 2 are new:
- the more link text --> not used in this new function
- stripteaser
- more file
- choose either "words" or "paragraph". Default is words.
- number of words or paragraphs to show in one page. Default is 380.
The function assumes words are separated by a space, and paragraphs by <br />\n<br /> (i.e. by 2 consecutive <br /> tags with a return in between). Users may wish to edit this string to separate paragraphs; simply look for this line and edit it:
Code: | $content = explode("<br />\n<br />" , $postdata["Content"]); |
Be aware that b2edit.php adds \n tags after every carriage return, hence the \n between both <br />.
The code could be improved so that both a max number of words and of paragraphs was user-set, but that's left for a future version.
That's all. Enjoy ! _________________ Albert Benzer
[ http://benzer.arkania.org ]
Last edited by Benzer on Mon Jul 28, 2003 7:53 pm; edited 1 time in total |
|
Back to top |
|
 |
epolady
Joined: 30 Jul 2002 Posts: 800 Location: Texas
|
Posted: Mon Jul 28, 2003 7:35 pm Post subject: Demo? |
|
|
Is there a demo of this somewhere? |
|
Back to top |
|
 |
Benzer
Joined: 23 Jun 2002 Posts: 31
|
Posted: Mon Jul 28, 2003 7:51 pm Post subject: |
|
|
If by demo you mean where is it working, yes: check out my own webpage -below the signature. _________________ Albert Benzer
[ http://benzer.arkania.org ] |
|
Back to top |
|
 |
Candle
Joined: 23 Dec 2002 Posts: 545
|
Posted: Mon Jul 28, 2003 8:39 pm Post subject: ........ |
|
|
I really don't care for sites that changes anything like my pointer etc . _________________ Play Aliens Awaken mY new Game . |
|
Back to top |
|
 |
Mizkie
Joined: 19 Mar 2003 Posts: 51 Location: Bloomington, IN
|
Posted: Mon Jul 28, 2003 9:36 pm Post subject: |
|
|
and the whole spanish thing doesn't help _________________ Mick
HSS = High School Sucks |
|
Back to top |
|
 |
Kiin
Joined: 10 Jun 2003 Posts: 21
|
Posted: Tue Aug 12, 2003 10:42 pm Post subject: |
|
|
Spanish has nothing to do with anything, you dont have to be able to read what he's saying to see the functionality of the script.
Hehe, can you tell, hablo espanol
-Kiin _________________ -Kiin |
|
Back to top |
|
 |
patrick
Joined: 22 Jul 2003 Posts: 4 Location: new jersey
|
Posted: Sat Aug 16, 2003 12:58 am Post subject: |
|
|
So, how exactly does it work? Is there an example of how it works (instead of see ind what it does)? _________________ o.O___patrick |
|
Back to top |
|
 |
Benzer
Joined: 23 Jun 2002 Posts: 31
|
Posted: Sat Aug 16, 2003 2:11 am Post subject: |
|
|
It's conceptualy simple: calls the mysql database of posts and slices the post either in words or in paragraphs; then displays as many of each as desired, and stores the starting point for the next page in a function passed with the url.
Since it calls the databse each time, it's not very efficient, but it's fine for short posts. It can be modified so it only calls the rigth part of the post in the database; if someone is willing tell me about it please.
Note also b2edit.php file will need adjustment on the function the_content: simply add two sets of quotes to go for the two extra parameters. _________________ Albert Benzer
[ http://benzer.arkania.org ] |
|
Back to top |
|
 |
sabadonaestrada
Joined: 08 Aug 2003 Posts: 6 Location: Brasil
|
Posted: Tue Aug 19, 2003 2:08 pm Post subject: |
|
|
Houston, We have a problem...
The problem is in "Admin Area".
Code: |
Warning: Missing argument 4 for the_content() in /home/ana/public_html/sabado/b2-include/b2template.functions.php on line 302
Warning: Missing argument 5 for the_content() in /home/ana/public_html/sabado/b2-include/b2template.functions.php on line 302
Warning: Division by zero in /home/ana/public_html/sabado/b2-include/b2template.functions.php on line 339
|
Must change code in b2edit.php, but I dont find the line with 'the_content' in this file.
What line??? I really dont find this function im b2edit.php
Can anybody help me?
Thanxs!! |
|
Back to top |
|
 |
Benzer
Joined: 23 Jun 2002 Posts: 31
|
Posted: Tue Aug 19, 2003 3:51 pm Post subject: |
|
|
Then follow the includes, let's see in which page the error is.
Also, you may need to declare the arguments making them equal to 0, in here:
Code: |
function the_content($more_link_text="(more...)",$stripteaser="0",$more_file="", $AB_choose_p_or_w=0, $AB_words=0)
bla bla ..
|
Indeed this hack is dangerous because it strikes at the cuore of b2; whoever is taking care of new versions of b2 should see if it's worth to add such a feature and do so in the general context.
Don't use the hack unless you know php. _________________ Albert Benzer
[ http://benzer.arkania.org ] |
|
Back to top |
|
 |
sabadonaestrada
Joined: 08 Aug 2003 Posts: 6 Location: Brasil
|
Posted: Tue Aug 19, 2003 10:58 pm Post subject: |
|
|
Thank you very much!!!
It's work... (partially)
The post is ok in "admin area", but the first line remains
Code: |
Warning: Division by zero in /home/ana/public_html/sabado/b2-include/b2template.functions.php on line 339
|
The line 339 of file b2template.functions.php is:
Code: |
$n_pages = intval($total_words / $AB_words) + 1;
|
But works... I can see and edit the post normally. |
|
Back to top |
|
 |
Benzer
Joined: 23 Jun 2002 Posts: 31
|
Posted: Thu Aug 21, 2003 12:45 pm Post subject: |
|
|
Make the variables $AB_choose_p_or_w and $AB_words be equal to something else by default, not to 0; like this:
$AB_choose_p_or_w=10, $AB_words=100
That may fix this division by zero when there are no arguments. _________________ Albert Benzer
[ http://benzer.arkania.org ] |
|
Back to top |
|
 |
sabadonaestrada
Joined: 08 Aug 2003 Posts: 6 Location: Brasil
|
Posted: Sat Aug 23, 2003 4:49 am Post subject: |
|
|
Thanxs Man!
It's work!
You are the best!
[]'s |
|
Back to top |
|
 |
sharmaine
Joined: 27 Oct 2003 Posts: 27
|
Posted: Wed Jan 14, 2004 4:11 am Post subject: |
|
|
Why is it that <!--more --> is not functioning in my b2? my b2 treated it as a html comment. thanks. |
|
Back to top |
|
 |
annia
Joined: 09 Apr 2002 Posts: 18
|
Posted: Thu Jan 15, 2004 3:05 pm Post subject: |
|
|
NEAT! Thanks! You are a lifesaver! |
|
Back to top |
|
 |
|