Shor intro on Homepage, Full intro on about us page

5 posts by 3 authors in: Forums > CMS Builder
Last Post: November 28, 2011   (RSS)

By jacgo - November 27, 2011

Hi, there

My about us page is "about_usDetail.php"
I would like have 4-5 lines shor about us content on Homepage "index.php"

When click "more detail..."
User can go "about_usDetail.php" for full information.

1) How to do the above issue?
2) Can I choose which paragraph for Homepage?

Thanks for help!

Jacgo

Re: [jacgo] Shor intro on Homepage, Full intro on about us page

By gkornbluth - November 27, 2011 - edited: November 27, 2011

Hi Jacgo.

It's pretty easy using a something called a function on your home page.

Here's a portion of a recipe from my on-line CMSB Cookbook http://www.thecmsbcookbook.com that describes the code you'll need and how to implement it.

Hope it helps,

Jerry Kornbluth

MAXWORDS - LIMITING THE NUMBER OF WORDS SHOWN ON A PAGE

NOTE: You'll have to load the table required (your about page) with a load records call at the top of your home page, and if your about page is a single record editor, you'll have to change the occurrences of $record in the example to $your_about_page_tableRecord.

If you use the character limiting function that’s exactly what you’ll get, and words can be cut off. But if you want to limit the word
count, Dave Edis from Interactive Tools shares his usual uncanny wisdom:

Insert this function at the top of your page, or before you want to invoke the word limiting function:

<?PHP
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);

return $output;
}
?>


Then put this code where you want the words limited to 5 words in this example:
<?PHP echo maxWords($record['content'], 5);
?>

If you want to add ...more and a link, use something like this:
<?PHP echo maxWords($record['content'], 5);
?>...<a href="<?php echo $record['_link']; ?>”>Read More</a>


or

<?PHP echo maxWords($record['content'], 5);
?>...<a class="read-more" href="http://www.your_site.com/your_detail_page.php?<?php echo $record['num'] ?>">(Read More)</a>

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

Re: [gkornbluth] Shor intro on Homepage, Full intro on about us page

By jacgo - November 28, 2011

Thanks for the quick reply.

I don't know how to post short intro on my Homepage from my "about_usDetail.php" page.

is there any one who know how to do?

Many thanks!

-jacgo

Re: [jacgo] Shor intro on Homepage, Full intro on about us page

Hi Jacgo,

You can display the contents of any text box field on any of your pages.

The maxwords function will limit the amount of words that show on your home page, and should give you the result that you want.

If you need more help, please be specific about what you've tried, what works, what doesn't, what code you've used, and what errors, you get if there are any.

I'm assuming that your "about" page gets its information from a single record editor field.

In your home page code, at the top, inside the PHP that loads the records for that page, you need to insert a load records call that looks like this, except that it has your about table name inserted.

// load records
list($your_about_tableRecords, $your_about_tableMetaData) = getRecords(array(
'tableName' => 'your_about_table',
'where' => whereRecordNumberInUrl(1),
'limit' => '1',
));
$your_about_tableRecord = @$your_about_tableRecords[0]; // get first record


Next, at the top of the body code of your page, you would insert the function that makes maxwords work.

<?PHP
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);

return $output;
}
?>


Then, in the body code, where you wanted the short intro from the about page to appear, insert this code, change the table name and field name to your names. Change the 5 to any number of words that you want to appear.
<?PHP echo maxWords($your_about_table['content'], 5);
?>...<a href="<?php echo $record[your_about_contents_field']; ?>”>Read More</a>


It sounds like you're pretty new at PHP coding for CMSB. My CMSB Cookbook http://www.thecmsbcookbook.com has a step by step beginners guide that can help you understand more about the process.

Best,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php