Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

All other Modules /

Discuss all other Modules here.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Article Holder - date descending?


Go to End
Reply


11 Posts   2558 Views

Avatar
FireMe!

Community Member, 74 Posts

14 February 2009 at 6:34am

Hi Guys

I'm new to SS and was just wondering if you guys could help me out with the Article Holder - to get it to have the articles to descend by date.

Ive added this to my ArticleHolder.php

function LatestNews($num=5) {
$news = DataObject::get_one("ArticleHolder");
return ($news) ? DataObject::get("ArticlePage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}


But when i go to the articleholder page it only displays ArticleHolder content, and not the Article Pages. But if i delete the above coding its will display the article pages but no in date decending its displayed in the order on there cms.

also this is my ArticleHolder.ss

<% control LatestNews %>
<div class="articleHolder"><br />
<div class="newsTitle">Latest News </div>
<div class="newsDateTitle"><a href="$Link" title="Read more on &quot;{$Title}&quot;">$Title</a></div>
<div class="newsDateTitle">$Date.Nice</div>
<div class="articleHolderClear"></div>
<div class="newsSummary">$Content.FirstParagraph <a href="$Link" title="Read more on &quot;{$Title}&quot;">more &gt;&gt;</a></div>
<div class="articleHolderFooter"></div>
</div>
<% end_control %>


am i missing something?

thanks in advance,

FireMe!

Avatar
Carbon Crayon

Community Member, 598 Posts

14 February 2009 at 7:02am

Hi FireMe!, welcome to SS :)

Your code looks generally good, so not sure what your exact problem is, but you can simplify your code to a single line like this which works for me:

function LatestNews($num = 5) {

return DataObject::get("ArticlePage", "ParentID = $this->ID", "Date DESC", "", $num);

}

Because you call the function from within the article holder you can use the $this variable which is the same your $news variable.

Hope that helps

Avatar
FireMe!

Community Member, 74 Posts

14 February 2009 at 7:19am

Hi aram, thanks for the quick reply and welcome, but it still does not seem to work, the homepage one works, but i cant get it do descend on the ArticleHolder page.

Avatar
Carbon Crayon

Community Member, 598 Posts

14 February 2009 at 8:11am

Hmm strange how about if you jsut reduce your get command to:

return DataObject::get("ArticlePage", "", "Date DESC", "");

Avatar
FireMe!

Community Member, 74 Posts

14 February 2009 at 8:34am

Still not working :-( i bet its something simple.

Avatar
Carbon Crayon

Community Member, 598 Posts

14 February 2009 at 8:43am

Edited: 14/02/2009 8:52am

ok....how about just

return DataObject::get("ArticlePage");

Just to make sure, this is in your ArticleHolder_controller class right?

Avatar
FireMe!

Community Member, 74 Posts

14 February 2009 at 9:45am

erm, im new to this sorry, im lost. if you could show me what i got to put in the ArticleHolder.php and what to put in the ArticleHolder.ss because i have tried every thing. :-(

Thanks in advance

Avatar
Carbon Crayon

Community Member, 598 Posts

14 February 2009 at 11:20am

Edited: 14/02/2009 11:28am

hehe no worries, let me explain :)

inside your ArticleHolder.php you should have 2 classes, the first which is called 'ArticleHolder' and extends Page is known as your page 'Model'. The model lays out the data that is stored in the database for each page and any mothods which are accociated with that data, for example the getCMSFields() method which creates the fields to edit data from within the CMS.

The second calss is your 'Controller'. It will be called 'ArticleHolder_Controller' and extends the Page_Controller. The controller is where all your methods relating to page logic go, for example functions for processing forms and returning DataObjects (like we are trying to do here).

Your template (ArticleHolder.ss) is known as your 'View' as it is what actually decides how all of the data in the model and the logic in the controller will actually be presented visually.

Together this makes the Model-View-Controller programming approach often reffered to as MVC.

So your controller for ArticleHolder might look like this:

class ArticleHolder_Controller extends Page_Controller {

function LatestArticles(){
DataObject::get("ArticlePage");
}

}

you can call any functions that you have defined in your controller (or your model for that matter) from with the pages template, either by using a control block <% control FunctionName %> or by calling it via a variable $FunctionName. It's also worth noting that you can only call controller functions from that pages template, so for example we could not call any functions from ArticlePage_Controller when we are on the ArticleHolder.ss template, but we can still call the functions which are in the ArticlePage model class.

So back to the question, if you put the above code into your ArticleHolder.php (in place of the controller that should already be there) does calling <% control LatestArticles %> work at all?

Anyway I hope I havn't confused you with all of that! If you have any questions just let me know :)

Go to Top