Articles Listing

7 posts by 4 authors in: Forums > CMS Builder
Last Post: October 1, 2010   (RSS)

URL: http://www.thevaleriefund.org/JT/news.php

I've created a 'news' page that is both the detail page and the listing page. So the detail of the first news section comes up.. then underneith, there's a list of archive news articles displaying only the first 5 articles in list form. This is all working perfectly with 2 viewers here's what I need....

1. in the list form, I want to display the title and only a few lines of the content. How do I show only a certain number of characters of a single section?

2. the viewer url is the same as the detail url, when clicking on an archive, it simply displays that detail on the page and still displays a list of the first 5 below it. In that list, I want to remove the item that's already being displayed.

3. then on a completely seperate page using the list view, I want to show ALL RECORDS, except for the first 5.

Your assistance is most appreciated.
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] Articles Listing

By Kenny - October 1, 2009 - edited: October 1, 2009

Here's some code I think you are looking for:

1. Limit Number of Words Shown


//Pre Head Code-----------------------------------

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;
}



//Page Code---------------------------------------

<?php echo maxWords($record['content'], 25) ?>




2. I'm not sure how this is working, can you provide a site example?



3. Add 'offset' => 4, to your top of page code to get to start at the 6th record. (record numbering starts at 0)


Kenny

Re: [sagentic] Articles Listing

thank you... all of this worked.. as for 2... here is the URL.. you'll see that the main article is "Camp Happy Times".. and at the bottom it says 'recent' news that lists the first 5 news listings... you'll see "Camp Happy Times" is one of them... but since that article is already showing on that page, I don't want it listed in one of the 5 at the bottom. http://www.thevaleriefund.org/JT/news.php
John Tedesco

Creative Director



JAM Graphics

Re: [jtedescojam] Articles Listing

By Kenny - October 3, 2009

OK - I'll admit that everything I tried didn't work when it comes to number 2. I'll have to pass this off the Dave or Chris.

[:(] Frustrated....


Kenny

Re: [sagentic] Articles Listing

By Chris - October 5, 2009

Hi jtedescojam,

2. the viewer url is the same as the detail url, when clicking on an archive, it simply displays that detail on the page and still displays a list of the first 5 below it. In that list, I want to remove the item that's already being displayed.


So you have two variables, I'll assume they're called $newsRecord and $newsRecords. $newsRecord is the selected record you're displaying details for, and $newsRecords is a list of the first 5 records. In your foreach which loops over $newsRecords, add the line of code in red below:

<?php foreach ($newsRecords as $record): ?>
<?php if ($record['num'] == $newsRecord['num']) { continue; } ?>


That will skip listing a record with the same record number (num) as the one you're displaying details for.

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [sagentic] Articles Listing

I have a question regarding this 'maxWords' code... I'm using this for news articles that include links and images... this code for somereason doesn't display links or images.. is there somethign we can do to this code to allow images and links provided it's within the max words?
John Tedesco

Creative Director



JAM Graphics