Developer forum

Forum » CMS - Standard features » RE: Items and most read

RE: Items and most read

Jan Sangill
Reply

Hi,

If I wanted to get the "most read" items under a itemtype, how could that be accomplished?

 

regards

jan


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Jan

Use datalists and something in the line of this:

SELECT        TOP (100) PERCENT COUNT(dbo.Statv2Page.Statv2PageID) AS antal, dbo.Page.PageID, dbo.Page.PageMenuText, dbo.ItemType_News.Heading
FROM            dbo.ItemType_News INNER JOIN
                         dbo.Page ON dbo.ItemType_News.Id = dbo.Page.PageItemId INNER JOIN
                         dbo.Statv2Page ON dbo.Page.PageID = dbo.Statv2Page.Statv2PagePageID
WHERE        (dbo.Page.PageItemType = N'News')
GROUP BY dbo.Statv2Page.Statv2PagePageID, dbo.Page.PageID, dbo.Page.PageMenuText, dbo.ItemType_News.Heading
ORDER BY antal DESC

This is for one of my item types - change it to the one you want to display.

Votes for this answer: 1
 
Jan Sangill
Reply

Hi Nicolai,

Perfect. Works like a charm.

 

A follow up question:

If I wanted to type this in razor and use database directly there. WOuld that be recommended, or would you still suggest datalist?

And If I wanted to use the DB directly in a razor template - could you provide an example?


 

 
Nicolai Høeg Pedersen
Reply

You could do it in Razor

string sql = "select something";
using IDatareader = Dynamicweb.Database.CreateDatareader(sql){

}

Something like that.

 
Mikkel Ricky
Reply
This post has been marked as an answer

The thread Razor templates - connect to database [http://developer.dynamicweb-cms.com/forum/templates/razor-templates-connect-to-database.aspx] contains some examples on getting content from the Dynamicweb database using Razor.

Best regards,
Mikkel

Votes for this answer: 1

 

You must be logged in to post in the forum