Developer forum

Forum » Development » Access Meta data of News Items

Access Meta data of News Items

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
Hi there,

I am using the following code to query news items:

var allNews = Dynamicweb.NewsV2.NewsItem.GetAllNewsValidAndActiveAndNotArchive();


This returns a collection of NewItem instances. But how do I access the meta data of the news item?

Imar
 


Replies

 
Nicolai Høeg Pedersen
Reply
Dynamicweb.Metadata.Common.GetNewsMetaData(_item.ID, "Title")
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hmmm, this smells like a N+1 problem, where I have 89 database calls for 88 news items, no?

I am creating my own News Url provider because the existing one seems broken and I would like to use the news meta title as the URL. Is this this the right approach to implement this?

Imar

 
Nicolai Høeg Pedersen
Reply
Yes - it is. Just checked...

The news module also have a field for the URL - that should be used if there, otherwise name of Newsitem.

You can download our source for the URLProvider here: http://developer.dynamicweb-cms.com/Downloads/Source-code.aspx

And it is not broken. The link is just not working. But &NewsId=XX just have to be the first parameter in the link.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
And it is not broken. 

 

Ah, that's good news. But does that mean that <!--@News:Href--> is broken then? I don't build up the URL myself, but retrieve it from this tag....
 


And to make things more confusing: even when I build up my own link it doesn't seem to work:
 

 <a href="Default.aspx?ID=<!--@Global:Page.ID-->&NewsId=<=!--@News:ID-->">....</a>

I also can't seem to access the PID tag here, so it looks like I *have* to use News:Href.

 

The news module also have a field for the URL

 

Do I have to do something for this field to show up? Can't find it when editing a news item.....
 


Imar
 
Nicolai Høeg Pedersen
Reply
I have it working here:
http://www.dynamicweb-cms.com/top-navigation/news.aspx

And it is also working on my local installation. And you do not need the NewsID first as I said, so this works as well:
<a id="news<!--@News:ID-->" href="<!--@News:Href-->"><!--@News:Date.ShortDate-->(<!--@News:CategoryName-->)&nbsp;<!--@News:Heading--></a>

So something else must be wrong... Link?

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
No link yet. It's on development only, and the test environment hasn't been updated to DW 7.2 yet. Will do that ASAP and post a link here.

In the mean time, did you find the URL field on the news item? Or is that DW 8?
 

Imar

 
Nicolai Høeg Pedersen
Reply
Oh - yes DW 8 again... Sorry.

Will have to start checking things on 7.2 branch!

But - I still have the news links working on a 7.2...

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I updated the site last night to the latest version of DW. You can find it here: http://test.nl.sapph.mediaweb.nl/ and the news page here: http://test.nl.sapph.mediaweb.nl/nieuws.aspx (which is a redirect from /Content/Nieuws in the backend).

The current SEO URLs are created with a custom URL Provider. Still needs some work as I need to strip odd characters from the URL. I just couldn't make it work with the default URL Provider and standards tags, but obviously I would like to....

Imar

 
Nicolai Høeg Pedersen
Reply
Ah - thanks.

Problem was that News (the old version) was not installed.

Installed it and now it should work. Will check the bug.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
Cool. Thanks!

Imar

 

You must be logged in to post in the forum