Introduction

cropped-sharepointhostingnews1.png

In a recent project I was asked to consult in, the team needed to create sub site/s for news or events. Developing for re-usability in SharePoint is something I find is lacking quite a bit in Development teams. Below I outline the solution I worked out for the project, that is also now a template that the Team can use in any similiar project. I will explain not only how to do it step by step but also continue to make this page layout as the default page layout of a publishing sub site. After that, make a content query in the root site to preview the news articles.

Finally, I will be using variation to create a similar publishing sub site in other languages. Step by step creation of News Page Layout using Content Type in SharePoint 2013.

How to Create a publishing sub site for news and using variation to creating the same site to other languages

  • Firstly open Visual Studio 2013 and a create new project of type SharePoint Solutions…”SharePoint 2013 Empty Project”.

sp1

  • Create new SharePoint 2013 empty project
  • As we will deploy our solution as a farm solution in our local farm on our local machine.

Note: Make sure that the site is a publishing site to be able to proceed.

2

  • Deploy the SharePoint site as a farm solution
  • Our solution will be as the picture blew and we will add three folders for “SiteColumns”, “ContentTypes” and “PageLayouts”.

3

  • SharePoint solution items
  • Start by adding a new item to “SiteColumns” folder

4

  • Adding new item to SharePoint solution
  • After we adding a new site column and rename it, add the following columns as we need to make the news layout NewsTitle, NewsBody, NewsBrief, NewsDate and NewsImage.

5

  • Adding new item of type site column to the solution
  • Then add the below fields and you will note that I use Resources in the DisplayName and the Group.

Collapse | Copy Code

After That

  • Create Content Type, we will be adding new Content Type to the folder ContentTypes

6

  • Adding new item of type Content Type to SharePoint solution
  • We must make sure to select the base of the content type “Page”.

7

  • Specifying the base type of the content type
  • Open the content type and add our new columns to it

8

  • Adding columns to the content type
  • Open the elements file of the content type and make sure it will look like this code below

Note: We use Resources in the Name, Description and the group of the content type.

  •  Add new Module to the PageLayouts folder. After that, we will find sample.txt file, then rename it “NewsPageLayout.aspx”

9

  • Adding new module to SharePoint solution.
  • Add the code below to this “NewsPageLayout.aspx”.
  • Don’t forget to add the Resources folder, then add the resource file with the name “SPWorld_News.resx” as we used it in the previous steps and add the below keys to it.
    • News : News
    • NewsBody : News Body
    • NewsBrief : News Brief
    • NewsContentType : News Content Type
    • NewsContentTypeDesc : News Content Type Desc.
    • NewsDate : News Date
    • NewsGroup : News Group
    • NewsImage : News Image
    • NewsPageLayout : News Page Layout
    • NewsTitle : News Title
  • Finally, deploy the solution.
  • The next steps will explain how we add the “news content type” to the page layout through SharePoint wizard. We will do these steps pragmatically in the next article.Note: We will do the steps from “A” to “D” pragmatically in the next article without the need to do it manually from SharePoint.

10

  • Go to Site Contents then Pages , Library, Library SettingsOpening library setting of the page library
  • Add the news content type to the page layout

11

  • Adding existing content type to the pages library then,

12

  • Selecting the content type to add it to pages library
  • Go to Pages Library, Files, New Document, select News Content Type

13

  • Adding new document of the news content type to pages library
  • Write the page title

14

  • Creating new page of news content type to pages library.
  • Open the page to edit it. Pages library contains new page of news content type

15

  • Now we can see the page Layout after we add the title, Body, Brief, date and image. Finally click Save the news

16