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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

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

Mulitple Article Holder Pages


Go to End


7 Posts   3388 Views

Avatar
innyinskip

Community Member, 46 Posts

28 July 2010 at 10:50pm

Hi Chaps,

Ive been following the tutorial here: http://doc.silverstripe.org/tutorial:2-extending-a-basic-site for creating an article system
which has been great. Got it working and very happy.

Ive then gone on to add the homepage controller which will show the 'Latest news' from the article page holder.
Which again has worked great.

My question is:
If i was to create 2 or more article holders with their article pages, could i like them both to work within the 'latest news' function?

EG:

IT News
---------> HomePage displaying the 5 latest news posts from both article holders?
HR News

HomePage.php
---------------------------------------------------------------
<?php
/**
* Defines the HomePage page type
*/
class HomePage extends Page {
static $db = array(
);
static $has_one = array(
);
}

class HomePage_Controller extends Page_Controller {

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

}

?>

--------------------------------------------------------------------------------
ArticleHolder.php
---------------------------------------------------------------------------------

<?php
/**
* Defines the ArticleHolder page type
*/
class ArticleHolder extends Page {
static $db = array(
);
static $has_one = array(
);

static $allowed_children = array('ArticlePage');
}

class ArticleHolder_Controller extends Page_Controller {

}

?>

I know this is a bit complicated but if someone could point me in the right direction i would be VERY graeteful!
Many Thanks
Craig

Avatar
Willr

Forum Moderator, 5523 Posts

28 July 2010 at 11:17pm

Well this is actually quite simple. If you look at the following function from that tutorial

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

This simply says get the children on 1 holder. If you have multiple holders you could make the function look like:

function LatestNews($num=5) { 
return  DataObject::get("ArticlePage", "", "Date DESC", "", $num);
}

Avatar
innyinskip

Community Member, 46 Posts

29 July 2010 at 12:43am

Will you truley are a legend.

Thanks very much!
Now just to have in in a section and scrolling mwah!! :)

Thanks again mate!

Avatar
innyinskip

Community Member, 46 Posts

29 July 2010 at 3:49am

Will,

Forgive me for being thick, but im wanting to have this as a small box at the bottom of the homepage scrolling up. V similar to this: http://www.yellowbrickroadconsulting.co.uk/

But rather than a widget more as a kind of footer scrolling up with the latest 4 or 5 posts.

Is that at all possible. Im havnig real issues even resizing it at the moment. Whatever i enter into the CSS its not resizing. Is it because of the type of control it is that it wont go smaller? (height wise?)
Many Thanks
Craig

Avatar
Willr

Forum Moderator, 5523 Posts

29 July 2010 at 11:07am

You probably need to make that div a set height then also need to set the overflow css property to hidden. Getting it to auto scroll you probably want to use jQuery to animate it.

Avatar
innyinskip

Community Member, 46 Posts

3 August 2010 at 7:17pm

Hi Will, Thanks for that.

I have managed to redesign it and get it the way i want but am having some major head issues with the jQuery.

From what i understand...

the JS files would have to be set in the 'Homepage.php' within the controller.
This is fine but i have also seen that this is required:

$('.myclass').vTicker({
speed: 500,
pause: 3000,
showItems: 3,
animation: 'fade',
mousePause: false,
height: 0,
direction: 'up'
});

Im not entierly sure where this would go. I have tried both in the template file and the page controller but nothing.
The ticker im trying to use is here:

http://www.jugbit.com/jquery-vticker-vertical-news-ticker/

Can you point me in the right direction please mate?

Thank you very much

Craig

Avatar
innyinskip

Community Member, 46 Posts

4 August 2010 at 4:02am

Not to worry, ive been playing about all day and FINALLY managed it!
(not the easiest task)

Last slight issue..

After doing all this all my current news pages seem to be invalid links.
New pages i create work but the ones previously dont...

I cant unpublish them in the cms they just give me a server error.
Is there a way to 'clean' items from the cms?

Thanks