Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Custom featured discussions by JS disappear when clicking views in Discussiosn list?

$
0
0

Hi, I have written the following code in JS and used in the home page of community site. This perfectly add a section that lists all Featured Discussions just above the 'new discussions' link. But when I click other views of discussions lists such as What's hot, my discussions etc.. the Featured section from the code gets removed unless it appears the page when I refresh the page. Is there a way to show all the time the Featured discussions from the code below?

$(function () {
            $.ajax({
                url: _spPageContextInfo.webAbsoluteUrl  + "/_api/web/lists/getbytitle('Discussions%20List')/Items?$select=ID,Title,Created,FileRef,ContentTypeId,CategoriesLookup/Title,CategoriesLookup/Id,BestAnswerId,Author/Title,Author/EMail,Author/FirstName,Author/LastName&$expand=Author/Id,CategoriesLookup/Id&$filter=(ContentType eq 'Discussion') and (IsFeatured eq 1)&$orderby=DiscussionLastUpdated desc",
                type: "GET",
                async: false,
                headers: {
                    "accept": "application/json;odata=verbose",
                    "content-type": "application/json;odata=verbose",
                },
                success: function (data) {
                 
                    var featuredText = "<span class = 'ms-textLarge'><b>Featured discussions</b></span></br>";       
                    itemCount = data.d.results.length;    
                   
                    itemCurrent = 0;
                    $.each(data.d.results, function (i, item) {                       
                        title = item.Title;                       
                        category = item.CategoriesLookup.Title;                       
                        categoryID = item.CategoriesLookup.Id;                        
                        FileRef = item.FileRef;
                        ContentTypeId = item.ContentTypeId;
                        url = _spPageContextInfo.webAbsoluteUrl + "/SitePages/Topic.aspx?RootFolder=" + FileRef + "&FolderCTID="+ ContentTypeId + "&SiteMapTitle=" + category + "&SiteMapUrl=/SitePages/Categories.aspx?CategoryID=" + categoryID + "%26SiteMapTitle=Categories";
                          featuredText += "<a href='" + url + "'><span class = 'ms-textLarge'>"+ item.Title + "</a></br>";
                    });

                    }

                    $('div.ms-comm-heroLinkContainer').prepend(featuredText);
                },
                error: function (error) {
                    console.log(JSON.stringify(error));

                }
            });


Viewing all articles
Browse latest Browse all 7589

Trending Articles