boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Turn posts into multiple pages without adding <!--more--&

 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Mon Jul 28, 2003 7:24 pm    Post subject: Turn posts into multiple pages without adding <!--more--& Reply with quote

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
View user's profile Send private message Send e-mail
epolady



Joined: 30 Jul 2002
Posts: 800
Location: Texas

PostPosted: Mon Jul 28, 2003 7:35 pm    Post subject: Demo? Reply with quote

Is there a demo of this somewhere?
Back to top
View user's profile Send private message
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Mon Jul 28, 2003 7:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Candle



Joined: 23 Dec 2002
Posts: 545

PostPosted: Mon Jul 28, 2003 8:39 pm    Post subject: ........ Reply with quote

I really don't care for sites that changes anything like my pointer etc .
_________________
Play Aliens Awaken mY new Game .
Back to top
View user's profile Send private message
Mizkie



Joined: 19 Mar 2003
Posts: 51
Location: Bloomington, IN

PostPosted: Mon Jul 28, 2003 9:36 pm    Post subject: Reply with quote

and the whole spanish thing doesn't help
_________________
Mick

HSS = High School Sucks
Back to top
View user's profile Send private message Visit poster's website AIM Address
Kiin



Joined: 10 Jun 2003
Posts: 21

PostPosted: Tue Aug 12, 2003 10:42 pm    Post subject: Reply with quote

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 Razz

-Kiin
_________________
-Kiin
Back to top
View user's profile Send private message
patrick



Joined: 22 Jul 2003
Posts: 4
Location: new jersey

PostPosted: Sat Aug 16, 2003 12:58 am    Post subject: Reply with quote

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
View user's profile Send private message
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Sat Aug 16, 2003 2:11 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
sabadonaestrada



Joined: 08 Aug 2003
Posts: 6
Location: Brasil

PostPosted: Tue Aug 19, 2003 2:08 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Tue Aug 19, 2003 3:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
sabadonaestrada



Joined: 08 Aug 2003
Posts: 6
Location: Brasil

PostPosted: Tue Aug 19, 2003 10:58 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Benzer



Joined: 23 Jun 2002
Posts: 31

PostPosted: Thu Aug 21, 2003 12:45 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
sabadonaestrada



Joined: 08 Aug 2003
Posts: 6
Location: Brasil

PostPosted: Sat Aug 23, 2003 4:49 am    Post subject: Reply with quote

Thanxs Man!

It's work!

You are the best!

[]'s
Back to top
View user's profile Send private message Visit poster's website
sharmaine



Joined: 27 Oct 2003
Posts: 27

PostPosted: Wed Jan 14, 2004 4:11 am    Post subject: Reply with quote

Why is it that <!--more --> is not functioning in my b2? my b2 treated it as a html comment. thanks.
Back to top
View user's profile Send private message
annia



Joined: 09 Apr 2002
Posts: 18

PostPosted: Thu Jan 15, 2004 3:05 pm    Post subject: Reply with quote

NEAT! Thanks! You are a lifesaver!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group