More in this section

Forums / Developing with Sitefinity / Tags and Providers

Tags and Providers

9 posts, 0 answered
  1. Matt
    Matt avatar
    22 posts
    Registered:
    25 Jan 2008
    24 Oct 2008
    Link to this post
    Hello-

    I'm working on a custom "related stories" control. The idea is to specify a tag and have the control show the 5 most recent articles from the News module that are tagged with that tag.

    I can use ContentManager.GetTags() to retrieve the Generic Content tags, but there doesn't appear to be a similar method for News. In fact, I can't find anything about tags in the News API. And the Tags API only talks about Generic Content. And since tags aren't shared across providers, I'm a little stuck.

    Can anyone share some pointers?

    Thanks!
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    28 Oct 2008
    Link to this post
    Hi Matt,

    Thank you for contacting.

    As I see it, the desired functionality can be achieved using our News View control.
    Here is what you need to do:
    1. Drag and drop NewsView control from the toolbox
    2. Go to settings and set "Limit the number of items for the entire list" to 5
    3. Go to advanced tab --> Filters
    4. Use the following FilterExpression
    Publication_Date <= "#now" AND Expiration_Date > "#now" AND Tag.Name = "mytag"

    You can get the tags by creating and instance of the Content Manager and specifying the provider as the example below demonstrates.

    Telerik.Cms.Engine.ContentManager manager = new Telerik.Cms.Engine.ContentManager("News"); 
    // get all news content items 
    IList listOfNewsItems = manager.GetTags(); 
     

    I hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. Matt
    Matt avatar
    22 posts
    Registered:
    25 Jan 2008
    28 Oct 2008
    Link to this post
    Thanks, Ivan. I know I can use the News View control, but I want to make it easier on my content providers than requiring them to edit the advanced properties of the control on every single page. With over 500 pages, that's a lot of work!

    I have the control basically functioning the way I would like using the NewsView object  and setting a bunch of filters. But what I can't figure out is how to work with the MasterSettings property to control what is shown in the control (want to reduce it to just titles). Is there any documentation on how to serialize data for this property?

    Thanks!
  4. Pierre
    Pierre avatar
    433 posts
    Registered:
    16 Feb 2006
    29 Oct 2008
    Link to this post
    Hi,

    Could you explain more how to catch the Tags and Categories added to one News article ( the edited article) in the codebehind added to the controlpanelEdit/Insert during creation mode. I search to use in one var. during one SaveButton2 event.
    Thanks.
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    31 Oct 2008
    Link to this post
    Hello Matt,

    If you want to hide the MasterSettings from the designer you need to change the control designer template located under the following path  ~\Sitefinity\Admin\ControlTemplates\News\Design\NewsViewControlDesigner.ascx.
    Otherwise, you can use the code provided in my previous post to get the NewsTitles or this one:

    / create new instance of NewsManager 
    Telerik.News.NewsManager newsManager = new Telerik.News.NewsManager("News"); 
    // get all news content items 
    IList listOfNewsItems = newsManager.Content.GetContent(); 
    if (listOfNewsItems.Count > 0) 
     foreach(Telerik.Cms.Engine.IContent newsItem in listOfNewsItems) 
         Response.Write(newsItem.GetMetaData("Title") + "<br />"); 

    If the above does not help please describe in details what exactly you want to achieve.

    Kind regards,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Matt
    Matt avatar
    22 posts
    Registered:
    25 Jan 2008
    06 Nov 2008
    Link to this post
    Thanks, Ivan. I switched over to using the NewsManager and your sample code. I have it working exactly the way I want, except I don't seem able to filter by the tag anymore. Previously, using NewsView, I was able to set the FilterExpression to Tag.name = whatever. That doesn't work with NewsManager?

    NewsManager news = new NewsManager("News");
    news.Content.FilterExpression = "Tag.Name = \"" + tag + "\"";

    This gives me: Invalid field name "Tag.Name".


    So, last question (I think): how do I filter based on tag names?
  7. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    07 Nov 2008
    Link to this post
    Hi Matt,

    Here is the code that gets the list of items for a meta key that has been tagged.

     protected void Page_Load(object sender, EventArgs e) 
        { 
            // create new instance of NewsManager  
            Telerik.News.NewsManager newsManager = new Telerik.News.NewsManager("News"); 
            //get list of items for Title meta key tagged with the specified Tag
            IList listOfNewsItems = newsManager.Content.GetContent(0, int.MaxValue, "Title""mytag");  
            if (listOfNewsItems.Count > 0)  
            { 
                foreach (Telerik.Cms.Engine.IContent newsItem in listOfNewsItems) 
                { 
                    this.news.Text += newsItem.GetMetaData("Title") + "<br />"
                } 
            } 
        } 

    I hope this helps.

    Greetings,
    Ivan Dimitrov
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. Nauman
    Nauman avatar
    35 posts
    Registered:
    28 Jul 2008
    27 Mar 2010
    Link to this post
    Hi Ivan Dimitrov

    Can you please tell me how i can add/map tags with the news API? Means  create news item with the news API and  also add/map tags during creation this news item.


    Thanks
    Nauman Ahmed
  9. Nauman
    Nauman avatar
    35 posts
    Registered:
    28 Jul 2008
Register for webinar
9 posts, 0 answered