popularanky
Posts: 53
|
Posted: 03/07/2012, 10:50 PM |
|
I have a website that is use to post information like blog. All I want is a code that will help me break from the second line of word and put the readmore link to a new page that shows the full details of the post. Like on blogs
_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive |
|
|
JayEdgar
Posts: 77
|
Posted: 03/08/2012, 8:41 AM |
|
That is a fairly complicated request for a forum like this. This would require a page or two of custom code.
|
|
|
clahti2
Posts: 107
|
Posted: 03/08/2012, 7:56 PM |
|
Quote popularanky:
I have a website that is use to post information like blog. All I want is a code that will help me break from the second line of word and put the readmore link to a new page that shows the full details of the post. Like on blogs
Hmmm...this is off the top of my head, untested. How are you getting the articles? I assume you are storing them in a database. Let's say you have a table called "articles" consisting of article_id and article_text. The article_id is the primary key and article_text field is a blob or whatever.
Now let's assume you have a page articles_summary.php and articles_detail.php. Place a grid on the summary page called articles, select * from articles table. Then on the grid populate two controls, one label control for {article_text} and one link control for {article_id}. Finally in the before show event for the {article_text}:
$pattern = '/\n/';
preg_match($pattern, $articles->article_text->GetValue(), $matches);
$articles->article_text->SetValue($matches[0]);
The above should shorten the label control to display the text up until the first line break. The {article_id} link control should have static text "Read More..." and link to articles_detail.php passing the parameter article_id. The detail page can then have a "record" which has a label showing the full article text.
|
|
|
popularanky
Posts: 53
|
Posted: 03/08/2012, 10:08 PM |
|
Quote :Hmmm...this is off the top of my head, untested. How are you getting the articles? I assume you are storing them in a database. Let's say you have a table called "articles" consisting of article_id and article_text. The article_id is the primary key and article_text field is a blob or whatever. Now let's assume you have a page articles_summary.php and articles_detail.php. Place a grid on the summary page called articles, select * from articles table. Then on the grid populate two controls, one label control for {article_text} and one link control for {article_id}. Finally in the before show event for the {article_text}: $pattern = '/\n/'; preg_match($pattern, $articles->article_text->GetValue(), $matches); $articles->article_text->SetValue($matches[0]); The above should shorten the label control to display the text up until the first line break. The {article_id} link control should have static text "Read More..." and link to articles_detail.php passing the parameter article_id. The detail page can then have a "record" which has a label showing the full article text.
I have tried the code and it return blank. Anyway, My table is called: problem and the field is: pro_desc, also on the grid. I have problem grid and pro_desc as the display column. this is the code
$pattern = '/\n/'; preg_match($pattern, $problem->pro_desc->GetValue(), $matches); $problem->pro_desc->SetValue($matches[0]);
and nothing is displaying on pro_desc column.
_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive |
|
|
popularanky
Posts: 53
|
Posted: 03/08/2012, 10:42 PM |
|
Getting this error now
Quote :Notice: Undefined offset: 0 in C:\xampp\htdocs\wimbid\Index_events.php on line 22
and line 22 is
$problem->pro_desc->SetValue($matches[0]);
_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive |
|
|
clahti2
Posts: 107
|
Posted: 03/10/2012, 1:18 PM |
|
Quote popularanky:
Getting this error now
Quote :Notice: Undefined offset: 0 in C:\xampp\htdocs\wimbid\Index_events.php on line 22
and line 22 is
$problem->pro_desc->SetValue($matches[0]);
Ok, I said my code was untested , try something like this:
$pattern = '/\n/';
$string = $problem->pro_desc->GetValue();
if (preg_match($pattern, $string, $matches, PREG_OFFSET_CAPTURE)) {
//we found a line break, get the offset
$offset = $matches[0][1];
$chopstring = substr($string,0,$offset);
} else {
//no line break, so just grab the first 100 characters;
$chopstring = substr($string,0,100);
}
$problem->pro_desc->SetValue($chopstring);
I tested this and it should work for you.
|
|
|
Wreckmaster
Posts: 48
|
Posted: 03/10/2012, 4:54 PM |
|
Hi clahti2 thanks for the code,
I was looking for some thing like this recently.
is there a simple piece of code which would allow me to chop at 100 characters for (sample) article-id and article-text ?
thanks again
|
|
|
popularanky
Posts: 53
|
Posted: 03/10/2012, 9:42 PM |
|
Hi Clahti2
I highly appreciate your support. your professional help has really help me solve the issue.
Thanks very Much. Will always remain grateful.
_________________
EKERE UBONG UBONG
IT Officer
CognitiveDrive |
|
|
drLeo
Posts: 12
|
Posted: 03/12/2012, 4:27 AM |
|
Quote popularanky:
Hi Clahti2
I highly appreciate your support. your professional help has really help me solve the issue.
Thanks very Much. Will always remain grateful.
Can do it with Jquery as well !
|
|
|
clahti2
Posts: 107
|
Posted: 03/12/2012, 9:51 AM |
|
Quote Wreckmaster:
Hi clahti2 thanks for the code,
I was looking for some thing like this recently.
is there a simple piece of code which would allow me to chop at 100 characters for (sample) article-id and article-text ?
thanks again
$chopstring = substr($string,0,100);
|
|
|
|