Homepage End Result

Homepage End Result

We created a solution a couple of years ago to give a client more control over the content exposed on the homepage. I am sharing it in this blog post in hope that it may spark creative ideas on using pbs:links and pbs:getcontent to solve other problems you may face on your sites.

 

The Problem Defined

The client is a weekly publication and has over 20 categories in which they publish stories. However, they focus on 3 different categories every week and wanted control to via the EI which of these 3 categories show on the homepage. They want to be able to decide which categories to highlight and to put them in the order they desire. We needed to choose a module in the EI that would let the editor turn categories off and on for that section as well as sort them.

 

The Logic

If we could find a module to allow the editors to essentially turn sections ‘off’ and ‘on’, we could list the ‘on’ categories in a template. But then what? We needed to render a category section with a header, top story and list of recent stories for each ‘on’ category. We decided upon creating a template that only renders the html for that category section, and then calling that template server-side with the pbs:getcontent tag to render it for each category the editor selected as ‘on’ for that week. We also chose the links module as a great way to let the editor select which categories should be shown on the home page.

 

Let’s go through each step and build this out.

 

 

 

StoryCreate template that outputs only the category section html for one category

We are going to build a template that generates html for just one category section. The url must have the category in it so we can use that category to generate the content. For the purposes of this exercise, we will assume we have the following categories:

  • CAT01
  • CAT02
  • CAT03
  • CAT04
  • CAT05
  • CAT06

 

Let’s build a template accessible by the URL
http://www.samplesite.com/section/CAT01&template=categorySection
which would be gen_categorySection.pbs. We will put the html and tag to generate the frontpage category section.
You will also, of course, need to create the news.pbo and newsitem.pbo files to render the newslist tag in this example. We’ll leave that to you.   Now, if we go to the url http://www.yoursitehere.com/section/CAT01&template=categorySection you should get a page that returns only the html for that specific category. Now that this is complete, we can move on to the next step to build up our frontpage with the categories selected by the editor.    

Set up links module

Set up links module

 

Setup Links Module

Now we need to setup the links module to allow the editor to select which categories to show. After it is setup, we can finish the template build. We create a new link category (frontpageCategories) and add each category as a link with the category as the title value and the link to the template we just created above as the link value. The links module is a little finicky the first time you create the new link category. Sometimes you have cancel out and go back in to create a new link for the category to show in the drop down.   Category Links Now that we have the category links all setup, we can use the pbs:links module on the homepage to list out only the sections that are ‘published’.   In the file below, we add the category id for the links category we just created above as the ‘maincategory’ parameter. With the sort parameter, we can allow the editor to put the links in the order they desire.

 

We then build out the object files for this link tag. You’ll notice that in the links item object file, we use the tag pbs:content to go pull the content from the template we created above.

 

You see we are passing a url into the getcontent tag that is set in the link. The variable <%currentURL%> is a system variable of the current site (www.tamberra.com in the URL of this page as an example). The variable <%url%> comes directly from the link item url parameter we setup above.

 

Since the links tag will only return link items that are ‘published’ and will sort them in the order set in the link object, we have just given the editor control of what shows on the home page.

 

We often use the getcontent tag in creative ways similar to how you would use AJAX calls on the client side. We use getcontent when we need the data returned server side for SEO reasons.

 

So how have you solved similar problems at your publication?