More in this section

Forums / Developing with Sitefinity / Retrieve News articles of particular language

Retrieve News articles of particular language

6 posts, 0 answered
  1. Shubhashini
    Shubhashini avatar
    4 posts
    Registered:
    07 Feb 2011
    02 Jan 2012
    Link to this post
    Plse help us to retrieve all Published News articles in particular Language.
    Ex: We have 4 languages (en, de, fr, it).
    When Current language is de, I need only articles published in de..
    Thanks..
  2. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    03 Jan 2012
    Link to this post
    Hi,

     In the database, there is actually only one news item entry for all available cultures. When you add a new culture, for each LString column in that table, a new column with the localization is added. So, when you get the items, you get only one for each localization. However, you can get the different localized properties for the different cultures. Here's a sample code on how to do that (gets the Content of the first NewsItem in the collection):

    NewsManager mng = NewsManager.GetManager();
                var news = mng.GetNewsItems().First().Content["en-US"];

    Kind regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Shubhashini
    Shubhashini avatar
    4 posts
    Registered:
    07 Feb 2011
    04 Jan 2012
    Link to this post
    NewsManager mng = NewsManager.GetManager();
    var news = mng.GetNewsItems().First().Content["en-US"];

    The above code displays content by considering a single News article.

    We need all news articles  content or data in corresponding languages.
    Which means while retrieving itself , we want to get news articles wrt respective languages.
    Is tat possible with Sitefinity API.

    Ex: If we have 15 news articles published in all the languages (en,de,it and fr),we need to display news content, title,etc wrt each language.
  4. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    04 Jan 2012
    Link to this post
    Hello,

     What you can do in such case is just get ALL of the news articles in one collection, then perform a foreach loop and for each item get the respective properties that you need, in the language that you need, just like I've shown you in the example (for every LString property, you can just type item.Property[culture] and get it for the respective culture).

    All the best,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Shubhashini
    Shubhashini avatar
    4 posts
    Registered:
    07 Feb 2011
    06 Jan 2012
    Link to this post
    Looping thru all News Item and taking Current cultures News articles worked.
    Thanks
    But before considering News item, it should be verified whether it is PublishedTranslations contains current culture. If it is published in Current culture, then only tat News Item has to be considered.
  6. Svetoslav Petsov
    Svetoslav Petsov avatar
    456 posts
    Registered:
    24 Sep 2012
    06 Jan 2012
    Link to this post
    Hello,

     I'm I was able to guide you in the right direction to solve the problem. You are correct about the check - do you need any help with that? Do not hesitate to contact me if you do.

    Regards,
    Svetoslav Petsov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
6 posts, 0 answered