How to create a News Detail Page

Hallo all,
I added a lot of fields to the news in the backend.

Now the news should be shown in a list view and in a detail view.
The list view works in oxid per default (tpl/page/info/news.tpl).

but now i also need a template news_detail.tpl to show just the details of a single news…

Basically I wonder how I create the links that will open then the detail page and I have to send a parameter (the ID of the news to be shown).

Is there any further configuration needed?

Kind regards,
Florian

all you need is to create a new View Class which would display the one of your news, something like “newsdetails”. For the beginning you can copy a existing View Class, e.g. “content” and edit/combine it with the news View to display a single news the way you want.

And you need a template for this view Class, which would display the details the way you want.

Just start with understanding the news view.

hey vanilla thunder,
thank you that worked quite well so far.

I´ve created /views/newsdetail.php
and
/out/mytemplate/tpl/page/info/newsdetail.tpl

In newsdetail.php I´ve put a function that does the db-request and returns an news object with all the properties that I need:

	
public function getNewsById($id){
    	$oDB = oxDb::getDb(true);
	$query = "SELECT * FROM oxnews WHERE oxid = '" .$id."'";
    	$row = $oDB->Execute( $query );
    	$news = new stdClass();
    	$news->titel = $row->fields["OXSHORTDESC"];
    	$news->datum = $row->fields["OXDATE"];
    	return $news;
}

and then I can use it in the tpl file like this:

[{assign var=“nid” value=$smarty.get.nid}]
[{assign var=“news” value=$oView->getNewsById($nid)}]
[{$news->titel}]

and finally the link to call the detail site looks like that:
[{assign var=“nid” value=$oNews->oxnews__oxid->value}]
<a href="[{ $oViewConf->getSelfLink()|oxaddparams:“nid=$nid&cl=newsdetail” }]">Weiterlesen</a>

Kind regards,
Florian

Hello,…
I found a little problem… the BreadCrumb does not work properly - contains just one link and it is wrong…

So far I have in newsdetail.php the same Breadcrumb function as in news.php:


public function getBreadCrumb()
    {
        $aPaths = array();
        $aPath  = array();

        $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_INFO_NEWS_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
        $aPath['link']  = $this->getLink();

        $aPaths[] = $aPath;

        return $aPaths;
    }
}

Is there a “cool” way to fix the breadcrumb, otherwise I will just get the news id from the parameters and do db request again to put to correct links in the breadcrumb.

Many thx,
Florian

i guess the bredcrub’s title is “nuigkeiten” and it points to the general news page, right?

the coolest way would be to fit

$aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_INFO_NEWS_TITLE', oxLang::getInstance()->getBaseLanguage(), false );
        $aPath['link']  = $this->getLink();

to your needs, so it would display what ever you want to.

$aPath[‘title’] might be something like $news->titel