+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / News Tags and Featured Image

News Tags and Featured Image

6 posts, 0 answered
  1. Simon
    Simon avatar
    3 posts
    Registered:
    19 Apr 2013
    19 Apr 2013
    Link to this post
    Hello,

    1. I am using the following code in the news widget to list all the tags of an news article. However, there are no links associated with the tags listed using this method. Could you tell me how I can display the tags with links associated with them?

    <sitefinity:FlatTaxonField ID="FlatFieldControl" DisplayMode="Read" runat="server" WebServiceUrl="~/Sitefinity/Services/Taxonomies/FlatTaxon.svc" AllowMultipleSelection="true" TaxonomyId="CB0F3A19-A211-48a7-88EC-77495C0F5374" TaxonomyMetafieldName="Tags" Expanded="false" ExpandText="ClickToAddTags" BindOnServer="true" /></a>

    2. Is there a way to associate a featured image with each news article in Sitefinity 5.4, just like the featured image or post thumbnail functionality in WordPress?
  2. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    23 Apr 2013
    Link to this post
    Hi Simon,

    Your requirement is achievable, but requires the modification of the news widget  template.

    First of all, the easier option would be to simply add a Tags widget to the page, where both widgets are configured. It will display all tags, used in the items as links, and you will be able to click on the and be redirected to the same page, but filter, according to the tag. Here's how to configure the tags widget:

    http://www.sitefinity.com/documentation/documentationarticles/user-guide/widgets/classifications-widgets-group/configuring-the-tags-widget

    That's the easiest approach. As I said, in case you'd like to add the tags under each content item and be able to click on each of them, you need to modify the templates of the news widget. Please find attached a modified template for the news widget. It suits the same scenario and the control, which is used to display news items is RadListView. I'll explain what we do and you can follow the same approach when customizing the list widget template:

    protected void Page_Load(object sender, EventArgs e)
          {
              NewsList.ItemDataBound += new EventHandler<Telerik.Web.UI.RadListViewItemEventArgs>(NewsList_ItemDataBound);
          }
       
          void NewsList_ItemDataBound(object sender, Telerik.Web.UI.RadListViewItemEventArgs e)
          {
              switch(e.Item.ItemType)
              {
                  case RadListViewItemType.DataItem:
                  case RadListViewItemType.AlternatingItem:
                      var listViewDataItem = (RadListViewDataItem)e.Item;
                      var dataItem = (NewsItem)listViewDataItem.DataItem;
                      if (dataItem != null)
                      {
                          var placeholder = e.Item.FindControl("CategoriesLabel") as SitefinityLabel;
                          placeholder.Text = RenderHierarchicalTaxaAsLink(dataItem, "Category");
                      }
                  break;
              }
       
          }

    We subscribe to the ItemDataBound event of the RadListView.Then when each item is bound we check whether it is a dataItem ,we get the item and the dataItem (which contains all properties of the items). In the template we have added a label, which displays our taxonomy items (in the sample - categories, in your case - Tags):

    var placeholder = e.Item.FindControl("CategoriesLabel") as SitefinityLabel;

    Then we call our RenderHierarchicalTaxaAsLink method (created by us). Here's the method and what it does:

    public string RenderHierarchicalTaxaAsLink(NewsItem newsitem, string taxonomyFieldName)
           {
       
               var catList = "";
               var categories = newsitem.GetValue<TrackedList<Guid>>(taxonomyFieldName);
               if (categories != null && categories.Count() > 0)
               {
                   catList = "Categories:</br> ";
                   var currentUrl = HttpContext.Current.Request.Url.ToString();
                   if(currentUrl.EndsWith("/"))
                   currentUrl = currentUrl.TrimEnd('/');
                   var taxManager = TaxonomyManager.GetManager();
                   foreach (var cat in categories)
                   {
                       var t = taxManager.GetTaxon<HierarchicalTaxon>(cat);
                       var url = string.Format("{0}/-in-{1}/{2}/{3}",currentUrl, t.Taxonomy.TaxonName, t.Taxonomy.Name, t.Name);
                       var link = string.Format( "<a href='{0}'>{1}</a><br/>", url, t.Name).ToString();
                       catList = catList + link;
                   }
               }

    It gets the taxonomy item, which is assigned to the list item and we construct the same link, which the Tags widget generates. For example:

    http://localhost:60876/testpage1/-in-Tags/Tags/testTag

    Where testTag is the chosen Tag. The only difference in your implementation of the method would be that you will get the tags, not the categories.

    For the second requirement you can check the following blog post, showing how to create a thumbnail selector for the news item content type:

    http://www.sitefinity.com/blogs/slavoingilizov/posts/slavo-ingilizovs-blog/2011/09/09/extend_the_image_selector_for_content_items_with_filtering_by_album

    All the best,
    Victor Velev
    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. Simon
    Simon avatar
    3 posts
    Registered:
    19 Apr 2013
    06 May 2013
    Link to this post
    Hi,

    Thanks for the reply. I have got two other questions.

    1. In my site, I have items of custom content type that belong to different category, and for each category, I have a specific page that displays items of only this category. However, when I put the tag widget onto this page, I noticed that it displayed tags of all items within all the categories that I had created. Could you tell me if there is a way to configure the tag widget so that it will only display tags of items of a custom content type within only a particular category?

    2. When I tried to create a search index for my site, I did not see any checkbox that allowed me to include the custom content types that I had created to the search scope. Could you please tell me how I can search the items of custom content types within sitefinity?

    Thanks,
    Simon
  4. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    08 May 2013
    Link to this post
    Hello Simon,

    If you want to show tags and categories, which are set only to one dynamic content type you can set the DynamicContentType property of the Categories or tags widget (you can see in in the Advanced setting of the widget) to the type of your custom module (dynamic). This will hide all other taxonomy links.

    On the second question, please take a look at the following article from our documentation:

    http://www.sitefinity.com/documentation/documentationarticles/user-guide/website-content/defining-search-indexes

    Kind regards,
    Jen Peleva
    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. Simon
    Simon avatar
    3 posts
    Registered:
    19 Apr 2013
    09 May 2013 in reply to Jen Peleva
    Link to this post
    Hi,

    Thank you for your reply. I know that I can change the DynamicContentType property to show tags that belong to a custom content type. The problem is that the tag widget does not allow me to filter tags by category. May I know how to show tags of items that belong to only a particular category, and these items are of custom content type? Do I need to create custom widget and do asp.net programming to achieve this?

    For the question of search index, I want to search the field "Title" and "Content" of the custom content type, so I entered "Title, Content" to "Additional fields for indexing" and reindexed the search index. However, I still could not get search results related to items of custom content type. Could you tell me if there are still additional settings that need to be done?

    Thanks,
    Simon
  6. Jen Peleva
    Jen Peleva avatar
    568 posts
    Registered:
    10 Nov 2016
    13 May 2013
    Link to this post
    Hi Simon,

     For your first requirement - yes, we don'y offer this out-of-the-box, so you'll need to create your own custom widget. You can take  a look at this blog post for guidance, where I'm modifying the default taxonomies widget (the Category and Tags widgets) to allow setting a parent category, so that only categories, which are child categories of this parent category will be displayed:
    http://www.sitefinity.com/blogs/jenpeleva/posts/jen-pelevas-blog/2013/05/10/how-to-create-a-categories-control-that-lists-sub-categories-in-sitefinity-cms
    At the moment this widget handles only taxonomies from one type - categories, tags or custom taxonomies only, so to create a widget that comnbines two types of categories, you may need to create your own widget.

    On the second problem you're experiencing, please take a look at the following KB about search troubleshooting:
    http://www.sitefinity.com/developer-network/knowledge-base/troubleshooting-search-problems
    Check if any information about eventual problem will be written in the error logs. Also, check if the property from the attached image is checked on your side, because if it is, it may be causing the indexing problem:

    Kind regards,
    Jen Peleva
    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