I know that when we people use a screen saver or a slider on our Home Pages we need to hard code our URLs for images or videos in our sliders to get it working.

Here I bring you a new concept of doing it without hardcoding the values.

I know it's tricky, but I learned the trick and soon you will too.

Here you see the following is an example of HTML code that we place in a content editor web part.

  1. <table cellpadding="0" cellspacing="0" class="slidingshell" style="width:25%;">
  2. <tr>
  3. <td>
  4. <a id="videoimg" ></a>
  5. </td>
  6. </tr>
  7. </table>
  8. <h2>
  9. <a id="videotitle" ></a>
  10. </h2>
  11. <h3>
  12. <p id ="videodescription"></p></br>
  13. <a id="clickurl"></a>
  14. </h3>
  15. </div>
  16. <!-- .slide-->
  1. $(document).ready(function() {
  2. var i=1;
  3. //Query your custom list here
  4. var query1 = "<Query><OrderBy><FieldRef Name='ID' Ascending='TRUE'/></OrderBy></Query>";

Assign the variables to an array, so that you don't need to call it every time.

  1. var valuedes=[];
  2. var valuetitle=[];
  3. var valueimgurl=[];
  4. var valuevideourl=[];
  5. var valueassettype=[];
  6. //Call SP Services to get all data from the list
  7. $().SPServices({
  8. operation: "GetListItems",
  9. listName: "CAROUSEL",
  10. async: false,
  11. CAMLQuery: query1,
  12. completefunc: function (xData, Status) {
  13. alert(xData.responseText);
  14. var test1 = xData.responseText;
  15. data1 = $.parseXML(test1),
  16. $test1 = $(data1);
  17. $(test1).find("z\\:row").each(function(){
  18. valuedescription[i]=$(this).attr("ows_Description");
  19. valuetitle[i]=$(this).attr("ows_LinkTitle");
  20. valueimgurl[i]=$(this).attr("ows_Preview_x0020_Picture_x0020_URL");
  21. valueimgurl[i]=valueimgurl[i].split(",")[0];
  22. valuevideourl[i]=$(this).attr("ows_Asset_x0020_URL");
  23. valuevideourl[i]=valuevideourl[i].split(",")[0];
  24. //It will start looping for all the IDs present in the group
  25. i=i+1;
  26. });
  27. }
  28. });

  29. var val1=[];
  30. var val2=[];
  31. var val3=[];
  32. var val4=[];
  33. var val5=[];
  34. for(var j=1;j<=i;j++)
  35. {
  36. val1[j]="<a id=\"videoimg"+j+"\" href=\"" + valuevideourl[j]+ "\" target=\"_blank\"><img src=\"" + valueimgurl[j] + "\" /></a>";
  37. val2[j]= "<a id=\"videotitle"+j+"\" href=\""+ valuevideourl[j] +"\" target=\"_blank\"> \""+ valuetitle[j] + "\"</a>";
  38. val3[j] = "<p id =\"videodescription"+j+"\">\""+ valuedescription[j] +"\"<a href=\""+ valuevideourl[j] +"\" target=\"_blank\"></a> </p>";
  39. val4[j] ="<a id=\"heading"+j+"\" href=\"#\">"+ valuetitle[j] +"</a>";
  40. }
  41. // Here the below code will append the HTML coding automatically, you need not everytime change the url and other details for every change in your Home Page.
  42. $('#videoimg').html(val1[1]);
  43. $('#videotitle').html(val2[1]);
  44. $('#videodescription').html(val3[1]);
  45. $('#clickurl').html(val5[1]);
  46. });

It will resolve many concerns, especially of the clients to pay the developers every time for making the HTML changes to their Home Pages so now they can change it on a list using a simple form and the result will exist directly on the Home Page without even touching the code.

For the developers it will save a lot of time especially when they don't have any.