Need to display latest news only

R G asked on March 15, 2024 10:27

In the news page displaying all the news, In home page I want dispaly latest 3 news only. If I try to add "News widget" in home page it's displaying all news. How to display lates 3 news in home page? Please help me.

Recent Answers


Liam Goldfinch answered on March 15, 2024 11:09 (last edited on March 15, 2024 11:09)

This really depends on how the widget has been built, do you have any code to share?

You need to modify the widget to have an option to restrict to latest news, and then amend the query it is running to use TopN(3)

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 15, 2024 14:47

Seems your news widget code needs to be updated to have a Top N property added so you can select this option. In most cases, we develop widgets to be multi-use. Meaning you can display all of the items, a subset of the items and tell the system how to order those items. This will most likely be a developer request.

0 votesVote for this answer Mark as a Correct answer

R G answered on March 19, 2024 06:37 (last edited on March 20, 2024 11:22)

where to add the condition on latest 3 article display to display, pls help me

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on March 19, 2024 09:22

It looks like the data access in your code is done in the ExecuteKenticoApi method, are you able to share that?

0 votesVote for this answer Mark as a Correct answer

R G answered on March 20, 2024 10:41 (last edited on March 27, 2024 08:40)

ExecuteKenticoApi Method

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on March 20, 2024 10:59

OK - so it looks like it is making a GET request to an API (presumably within the same codebase) by using the URL generated in the first method, so you'll need to pass a topN parameter in the URL like this:

var url = _appSettings.APIBaseUrl + "ContentItemsHierarchy?pageAliasPath=" + strPath + "&siteName=" + _appSettings.SiteName + "&publishedOnly=true&culture=" + _appSettings.Culture + "&topN=3";

Then you need to figure out where the ContentItemsHierarchy API method lives, and modify the data access within that to use the new topN parameter.

0 votesVote for this answer Mark as a Correct answer

R G answered on March 20, 2024 11:08 (last edited on March 27, 2024 08:39)

I want to display home page , not displaying all news.

0 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on March 20, 2024 16:28

R G, you need to parameterize your widget, pass that TOPN parameter through to your ExecuteKenticoAPI method, then pass that through to your API url string builder. I'd suggest setting the property default to -1 which will display all items. Then allow the user to enter any number if they wanted to limit it to say 3 or 10.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.