Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marina 10 posts 30 karma points
    Apr 29, 2015 @ 13:32
    Marina
    0

    Issues with News widgets

    Hi, 

    We have a News section and a News widget on our homepage, as well as a side News widget on several landing pages. Both widgets show the 3 latest articles. 

    I have the following problems with the widgets:
    - When clicking on a news category under one of the 3 articles on the Homepage widget, I am redirected to the actual article, instead of the page with all articles from that category
    - When clicking on a news category under one of the 3 articles on the landing pages side widget, I am redirected to the main News landing page, instead of the page with all articles from that category
    - If an article has a link in its first few lines, the link and the words associated with it do not appear on the Homepage and landing pages snippets. 

    Any help and suggestions on how I can fix this would be greatly appreciated. 

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Apr 29, 2015 @ 16:47
    Alex Skrypnyk
    0

    Hi Marina,

    Welcome to community )

    Can you show code of your views ?

    What version of Umbraco are you using ?

    Thanks, Alex

  • Marina 10 posts 30 karma points
    Apr 29, 2015 @ 18:01
    Marina
    0

    Hi Alex, 

    Thank you for your reply.
    I'm using Umbraco 7.1.4.

    I've actually managed to fix the issue on the Homepage widget.
    I've replaced <a href="@child.Url" with <a href="@(child.Parent.Url)?cat=@(category.UrlName)" in the Partial View Macro Files template. 

    I've tried doing the same for the landing pages side widget but it doesn't work. 
    What is strange is that the code is the same than the one used on the Homepage News widget (@child.Url), but the behaviour is different (redirection to all articles instead of the viewed article). 

    Here is the code for the side widget:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage 

           @{

               var newsNode = Model.Content.AncestorOrSelf("Home").Descendant("NewsLanding");

    <h3 class="giga">Latest news</h3>

    <ul class="lister">

    @{

               foreach (var child in newsNode.Children.Where(c => c.DocumentTypeAlias == "NewsArticle").OrderBy("newsDate desc").Take(3))

               {

                   <li class="push-bottom">

                         @{

                             var dateDay = child.GetPropertyValue<DateTime>("newsDate").Day;

                             DateTime? dateMonth = child.GetPropertyValue<DateTime>("newsDate");

                             var dateYear = child.GetPropertyValue<DateTime>("newsDate").Year;

                         }

                       <p class="muted flush"><strong>@dateDay @dateMonth.Value.ToString("MMMM")</strong></p>

                       <h2 class="mega push-small--bottom"><a href="@child.Url">@(child.GetPropertyValue<string>("newsTitle"))</a></h2>

                        @{

                                    IPublishedContent author = Umbraco.TypedContent(child.GetPropertyValue<int>("authorPicker").ToString());

                                    IPublishedContent category = Umbraco.TypedContent(child.GetPropertyValue<int>("categoryPicker").ToString());

                                    if (author != null || category != null)

                                    {

                                        <p class="muted gamma">Posted by @author.Name in <a href="child.Url" title="@category.Name">@category.Name</a></p>

                                    }

                                    else

                                    {

                                        <p class="muted gamma">Posted <a href="@child.Url">@child.Name</a></p>

                                    }

                                }

     <p class="push-half--bottom">@Umbraco.StripHtml(Umbraco.Truncate(Html.Raw(child.GetPropertyValue<HtmlString>("newsArticle")), 250))</p>

                       <a class="gamma push-large--top" href="@child.Url" title="@child.Name"><strong>Read More</strong></a>

                   </li> 

               }

           }

               </ul> 

  • Marina 10 posts 30 karma points
    May 06, 2015 @ 10:17
    Marina
    0

    Anybody knows how I can fix this?
    No matter what changes I make to the side widget code, I always get the same result, it redirects to the main news landing page but with a different url.
    Any help would be very much appreciated.
    Thanks! 

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 06, 2015 @ 10:31
    Alex Skrypnyk
    0

    Hi Marina,

    I made some fixes and now code looks like :

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    @{
    
        var newsNode = Model.Content.AncestorOrSelf("Home").Descendant("NewsLanding");
    }
    
    <h3 class="giga">Latest news</h3>
    
    <ul class="lister">
    
        @{
    
            foreach (var child in newsNode.Children.Where(c => c.DocumentTypeAlias == "NewsArticle").OrderBy("newsDate desc").Take(3))
            {
    
            <li class="push-bottom">
    
                @{
    
                var dateDay = child.GetPropertyValue<DateTime>("newsDate").Day;
    
                DateTime? dateMonth = child.GetPropertyValue<DateTime>("newsDate");
    
                //var dateYear = child.GetPropertyValue<DateTime>("newsDate").Year;
    
                }
    
                <p class="muted flush"><strong>@dateDay @dateMonth.Value.ToString("MMMM")</strong></p>
    
                <h2 class="mega push-small--bottom"><a href="@child.Url">@(child.GetPropertyValue<string>("newsTitle"))</a></h2>
    
                @{
    
                IPublishedContent author = Umbraco.TypedContent(child.GetPropertyValue<int>("authorPicker").ToString());
    
                IPublishedContent category = Umbraco.TypedContent(child.GetPropertyValue<int>("categoryPicker").ToString());
    
                if (author != null || category != null)
                {
    
                    <p class="muted gamma">Posted by @author.Name in <a href="@category.Url" title="@category.Name">@category.Name</a></p>
    
                }
    
                else
                {
    
                    <p class="muted gamma">Posted <a href="@child.Url">@child.Name</a></p>
    
                }
    
                }
    
                <p class="push-half--bottom">@Umbraco.StripHtml(Umbraco.Truncate(Html.Raw(child.GetPropertyValue<HtmlString>("newsArticle")), 250))</p>
    
                <a class="gamma push-large--top" href="@child.Url" title="@child.Name"><strong>Read More</strong></a>
    
            </li> 
    
            }
    
        }
    
    </ul>
    
  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 06, 2015 @ 10:36
    Alex Skrypnyk
    0

    Problem was in this lines:

    <p class="muted gamma">Posted by @author.Name in <a href="child.Url" title="@category.Name">@category.Name</a></p>
    

    href attribute is wrong, you have to write:

    @category.Name

    Thanks, Alex

  • Marina 10 posts 30 karma points
    May 06, 2015 @ 10:45
    Marina
    0

    Hi Alex, 

    Thanks for your reply but it doesn't fix it unfortunately. 
    As I said, it seems that whatever I replace the href attribute with, I get the same result for some reason. 

    Currently, when I click on the 'Extraordinary News' category on the first article in our homepage news widget, it redirects to the following url (the correct page):
    news/?cat=extraordinary-news

    If I click on the 'Extraordinary News' category on the first article in our side news widget, it redirects to this page (wrong one as it actually lists all our articles, instead of just the ones under the 'Extraordinary News' category):
    news/categories/extraordinary-news/

    Any ideas? 

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 06, 2015 @ 10:56
    Alex Skrypnyk
    0

    Marina, can you share your code ? and structure ? Maybe something with these lines :

    IPublishedContent category = Umbraco.TypedContent(child.GetPropertyValue<int>("categoryPicker").ToString());
    

    Thanks

  • Marina 10 posts 30 karma points
    May 06, 2015 @ 11:25
    Marina
    0

    I'm sorry my knowledge is quite limited. I'm not a web developper, I'm just trying to fix something that was not done properly so I'm not sure where you need me to look. On top of the news widget and side news widget, I've also got a news categories partial view macro file, so I'm hoping that's what you are looking for:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage 

    @*<aside role="complementary" class="medium-4 large-3 pull-left-tablet">

               <div class="push-large--bottom">

                       @{

                           var catNode = Model.Content.AncestorOrSelf("Home").Descendant("CategoryFolder");

                           string category = Request.QueryString["category"];

                       }

              <h2 class="giga">@catNode.Name</h2>

                            <ul class="lister lister--links">

                                <li class="active"><a href="#" class="all">All</a></li>

                                @foreach (var catID in catNode.Children.Where(c => c.DocumentTypeAlias == "Category"))

                                {

                                      <li><a href="@?cat=@(catID)" class="@catID.UrlName">@catID.Name</a></li>

                                }

                            </ul>

               </div>

    @Umbraco.RenderMacro("_StayInTouchWidget")

    </aside> *@       

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 06, 2015 @ 11:58
    Alex Skrypnyk
    0

    Marina, you have to use this link:

    <a href="@?cat=@(catID)" class="@catID.UrlName">@catID.Name</a>
    

    In your partial with child news. Like this :

    <p class="muted gamma">Posted by @author.Name in <a href="@?cat=@(category.Id)" title="@category.Name">@category.Name</a></p>
    

    Thanks

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 06, 2015 @ 12:00
    Alex Skrypnyk
    0

    It's great that non-developers are making changes in Umbraco )) It means that Umbraco is really simple and customizable.

    Thanks

  • Marina 10 posts 30 karma points
    May 06, 2015 @ 12:16
    Marina
    0

    Still doesn't work :-(. 
    No matter what changes I make to the side news widget partial view macro file, the url I am directed to remains exactly the same: news/categories/extraordinary-news/
    This did not happen when I was trying to fix the news widget on our homepage. I had many partial view macro errors before I managed to fix it. 
    So it makes me think that maybe what I need to modify is located somewhere else... 

    And yes I agree, it's amazing that without previous developping knowledge, but just by looking at previous issues and asking the community, I'm able to fix things ;-). Struggling with that one though ahah.  

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 06, 2015 @ 12:28
    Alex Skrypnyk
    0

    Try to remove all code )) you will see is it view what you need or no.

  • Marina 10 posts 30 karma points
    May 06, 2015 @ 13:09
    Marina
    0

    Fixed it! That's what I thought, it was located somewhere else.
    Seems like we have a side news widget that is not used so obviously, making changes there couldn't fix my problem.

    Now the only remaining problem for both homepage and side news widgets is the fact that in-text links do not show/work.
    If I have an article that has a link in the first few lines:
    - the link doesn't show
    - the actual words used in the text for the link do not show either so I end up with nonsense sentences such as:
    "Learn more about our new [missing linked words] here"

    The only work around I've found so far is not to put links in the first few lines of any article but of course that is not ideal.
    Any suggestions on how to fix this? 

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 06, 2015 @ 14:59
    Alex Skrypnyk
    0

    Marina, are you using rich text editor for inserting links ? Can you look at view source of page ?

    Thanks, Alex

  • Marina 10 posts 30 karma points
    May 06, 2015 @ 15:24
    Marina
    0

    I believe I am. 

    Here is the code for the snippet when I look at view source of page:
    <p class="push-half--bottom">Microsoft’s Cloud and Hosting Summit in Seattle is an invite only event bringing together some 700 delegates drawn from [missing link and word "Microsoft"]’s hosting partners around the world. Here are some insights from the conference.&hellip;</p>

    Here is the source code when I am editing the page in Umbraco:
    <p>Microsoft’s Cloud and Hosting Summit in Seattle is an invite only event bringing together some 700 delegates drawn from <a href="https://www.microsoft.com/en-gb/default.aspx">Microsoft</a>’s hosting partners around the world. Here are some insights from the conference.  </p>

    And here is the code for the page template:
    <p class="push-half--bottom">@Umbraco.StripHtml(Umbraco.Truncate(Html.Raw(article.GetPropertyValue<HtmlString>("newsArticle")), 250))</p>

    I just read something saying that Umbraco.Truncate doesn't keep the formating. Is there a another way of writing this so that I can keep the original formating (we don't use bold or colors so it's mainly being able to keep links and the words associated with them).

    Thanks again Alex for all your help so far. 

     

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    May 07, 2015 @ 07:57
    Alex Skrypnyk
    0

    Hi Marina,

    Try to insert link like that:

    <p class="push-half--bottom">@Html.Raw(article.GetPropertyValue<string>("newsArticle"))</p>
    

    Or just :

    <p class="push-half--bottom">@article.GetPropertyValue("newsArticle")</p>
    

    Truncate isn't good solution for text with html, because it can produce broken html code.

    Maybe it would be better to create another field at this document type, something like 'Summary' text, where max-length will be 250 symbols, and you will not need to use Truncate than.

    Thanks, Alex

  • Marina 10 posts 30 karma points
    May 08, 2015 @ 16:24
    Marina
    0

    If I use any of the 2 options you suggest, the entire article is showing, instead of only part of it. 
    Also, it shows both links and images, whereas all I need is for links to show (or at least for linked words not to be 'truncated'). 

    Adding another field to the document type means we'd have to input this manually everytime we publish a new article.
    At the moment the News landing page as well as the widget on the Homepage and side widget on the other landing pages are automatically populated once we publish a new article.

    Ideally what I would need is something similar to @Umbraco.Truncate which shortens the content and doesn't get rid of the links but without showing pictures.
    I'm not sure that is even feasable.

    I would already be happy with a function that shortens the text and can at least keep linked words in plain text.
    If the clickable link is not there but the word is there, at least the sentence makes sense. Does anything like this exist?


     

  • schlubadub 102 posts 617 karma points
    May 15, 2015 @ 02:42
    schlubadub
    0

    @Marina - just remove Umbraco.StripHtml as that is stripping out the HTML (and hence the links) from your page:

    <p class="push-half--bottom">@Umbraco.Truncate(Html.Raw(article.GetPropertyValue<HtmlString>("newsArticle")), 250)</p>

    But then you would still have the images...

    Have a look here as it discusses both the Truncate and StripHTML functions: http://umbraco.com/follow-us/blog-archive/2011/9/22/umbraco-razor-feature-walkthrough%E2%80%93part-8

    So I would assume you could do something like this (I haven't tested that it works):

    <p class="push-half--bottom">@Umbraco.StripHtml(Umbraco.Truncate(Html.Raw(article.GetPropertyValue("newsArticle")), 250), "img")</p>

    If that doesn't work you can try your own module such as this: http://stackoverflow.com/questions/17048469/remove-img-tag-from-html-raw-in-razor-view

     

  • Marina 10 posts 30 karma points
    May 15, 2015 @ 11:28
    Marina
    0

    Hi, 

    Thanks for your help. I appreciate it.
    Unfortunately, I have already tried removing Umbraco.StripHtml and looked at the first link you sent. I still get the same result, no link and the words associated with it truncated. And I also agree that I would still have a problem with any articles which has an image in its first paragraph.

    From what I've read, Umbraco.Truncate seems to be the problem because it doesn't handle well rich text.

    You last link is interesting. However, my web developping knowledge is more than limited and I'm not sure where I am supposed to add the following:

    You can create you own Extension Method for this as below:

    publicstaticclassStringExtensions{publicstaticstringSkipImgTags(thisstring html,int length){string strWithoutImgTags =Regex.Replace( html,@"(<img\/?[^>]+>)",@"",RegexOptions.IgnoreCase);return strWithoutImgTags.Substring(strWithoutImgTags.Length- length);} 

    } 

Please Sign in or register to post replies

Write your reply to:

Draft