Skip to content

Instantly share code, notes, and snippets.

@lokothodida
Created August 16, 2015 19:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lokothodida/f592ddc3d3839c8977ec to your computer and use it in GitHub Desktop.
Save lokothodida/f592ddc3d3839c8977ec to your computer and use it in GitHub Desktop.
GetSimple tutorial for creating a news system with the i18n plugin(s) (version 3)

Hello dear reader, and welcome back to another session of GetSimple tutorial fun! We return to the subject of news and how to attain a functional news plugin for the GetSimple CMS. A lot of changes have been made since last we met, both to the core functionality of the CMS and to the plugins themselves. But let's get everybody up to speed now, shall we?

A CMS or content management system is a piece of software that does as told: managing content. It acts as a portal from which you can manage a website and its contents with much greater ingenuity and control than you could manually or from scratch. On the end of the spectrum with larger file sizes reside the very well known CMSs, such as Wordpress, Drupal and Joomla; lower down with smaller file foot-prints we have the modest yet superlatively potent GetSimple. The benefit of CMSs such as GetSimple is that they are flat-file CMSs; that is, you don't need to install a database in order to make them work as you would with larger CMSs. This makes them not only easier to install, but allows for users to install GetSimple even if their webspace doesn't allow them to have databases, which is the major hindrance of the bigger management systems.

The initial downside to GetSimple is that to keep the file size as low as possible, only core functionality is included on the CMS, meaning that you can only upload files and create basic pages. You aren't able to have extra users, a contact form, a news feed and so on. But, just as easily as you can install the software itself, you can also install plugins which give you access to these functions, and if there is one thing that the GetSimple community is strongest for, it's for having a thriving community of plugin developers and test users.

When I first wrote this article (Version 3, that is), I thought I'd just give a rundown of what to do, rather than explaining what each individual plugin did towards the ultimate goal, simply because it would take a while to explain. But as I've been rewriting and redrafting this piece, I've realised that it is better to include this section at least for the sake of completeness; you can skip to here if you are in a rush, but to better understand what the purpose is of what you're doing, please read below....

Purpose of the Plugins

Ultimately what we are looking to have at the end of this tutorial is a fully-functional module or plugin that enables us to publish news articles. There are complete self-contained news article plugins on GetSimple that one can use, and one is rather popular because of how easy and quick it is to set up. But its greatest limitation is ironically in the fact that it is separate and self-contained; news articles are not pages but their own separate 'thing', so they are difficult to index and search as any other page on your site would. On top of that we run into problems of functional breadcrumb trails, how the links on your site follow to those news articles correctly and generally we have a lack of options to customise your news outputs visually. It is a perfect little tool for setting up a basic news system for a client, but isn't potent enough to give free reign to those who want creative freedom.

This is why I am suggesting that to produce news on GetSimple, you should use the following plugins:

  • i18n
  • i18n Search
  • i18n Special Pages

These plugins were created by master developer mvlcek whose design philosophy is that we should avoid making completely separate content types because it confuses search engines and leads to very messy problems on the back-end. Ideally, if we want different content types, we should simply be using pages with special features added to them which give them their status: a regular page is a regular page, a news page is a regular page with extra features applied onto it which distinguish it, such as an author field, an email field, an avatar, a summary etc. This makes organisation easy and elegant whilst allowing for a number of design possibilities only limited by your own abilities and imagination.

I18N improves the core page management functionality of GetSimple and allows for pages to be made in multiple languages. If you have a multilingual reader-base, this is an essential plugin regardless of whether you want to include news or not.

I18N Search provides an internal search-engine for your site so that users can easily find the pages that they want. When a search index is configured in a particular way, you can make it such that the only results are a) news items b) ordered in a way that you specify and c) styled such that they look like news items which include all of the relevant information that you want.

Lastly, the newest addition (arguably the most important one) is I18N Special Pages, which allows you to define a special type page with its own unique fields. If you make a news-type page with news-type fields, you can then create your news articles using this plugin and they'll have all of the news properties that you've defined, whilst still being searchable with I18n Search as any other page would.

When combined together, Special Pages lets you define how the news article looks; Search lets you define how the entries look when listed on the 'News' page and i18n itself makes everything easier to manage. So with this all in mind, let's get cracking!

What you will need:

The Installation Process

Note: I am doing this with GetSimple Version 3.1, so if you have an earlier version certain aspects of the admin panel may look slightly different. Don't worry about that. However, please consider upgrading to the latest stable version as soon as possible to ensure that your plugins work correctly.

Firstly, ensure that your webspace provider actually has the specs needed to run GetSimple. Check the limitations that the provider places on you (for example, what version of PHP are they running?) and check that against what the GetSimple site specifies, because you don't want to be in a position where you can't progress in this tutorial due to a hindrance you weren't aware of.

With that known, unzip GetSimple to your webspace, then when that has finished, open the 'index.php' file in your web browser to start the installation process. For more details, visit the GetSimple site. Then in your file manager, go to the /plugins folder of your installation, and unzip the following files to that directory in order to install them:

  • i18n.zip
  • i18n-search.zip
  • i18n-special-pages.zip

There are more plugins and files that you can install later on which will improve the functionality of the news system, but these are the only things needed to ensure smooth ride.

Building up your news system

Go to 'Settings' (on the right) and look at the 'Custom Permalink Structure' field. You can click the 'more' link for extra information on how to set this up, but basically just make sure that you can have your own custom link structure (you being unable to would be a result of your webspace provider having limitations). Tick the 'Use Fancy URLs' and click 'Save Settings'. You can use this as your default for now:

%parent%/%slug%/

The purpose of this is so that a) you have a more logical structure to your links, making them easier to follow and b) there is a function regarding the Search plugin that requires fancy URLs. If you cannot do this, don't worry – it is just a nice thing to have; the links (which aren't a necessity) simply won't lead to anywhere, and you can disable that functionality later (I'll tell you how to when it comes up).

Now download this file and unzip it to the root directory of your GetSimple installation.

i18n-news.zip

Contained are a basic News page (already pre-configured), a Search page (which has the search form on it) and an extensive template for your news Special Page.

Note: You may need to chmod the following files to 755 so that they can be edited in the GetSimple admin console afterwards:
  • i18n-news.xml
  • i18n-search.xml

Click on the 'Plugins' tab and then 'Configure I18N Special Pages' on the right and you should see this.

Click the 'I18N News' from the 'Or create a special page type from one of the templates' list and click 'Save Special Page Type'. You have now set up your special page type and are already ready to start posting news!

To do so, go to the 'Pages' tab and click 'Create New Special Page' and 'I18N News'. Initially, you have what looks like a regular page for you to edit. However, when you click Page Options, you'll see something magical....

You now have a series of new fields that only exist on news pages! Fill in all of the relevant fields and click save. The way that I've set it up is that you don't need to fill in the summary field if you don't want to – if you haven't, the News page will just show an excerpt from the main content.

Go to 'Pages' and the click '# 'sign where 'News' is to view your results.

The 'News' page lists all of the news entries you have available. When you click on the entry title it takes you to the page itself, which shows the full news entry and a few other pieces of information.

And there we have it! To produce news articles simply go to 'Create New Special Page' and 'I18N News', define your content and save! Don't worry about them looking ill-positioned and just generally unattractive - you can style the individual elements yourself till you have things looking exactly as you want, which is what you will next see how to do.

Configuration

The current setup should do the following for you...

  • Give your article:
    • a subtitle
    • an author (and their email address; get rid of the 'mailto' to make it a normal URL)
    • an avatar for the author
    • a category (which you will learn to define in a moment)
    • a summary if you so choose to have a custom one
  • Whilst automatically...
    • Ordering the articles by their creation date (newest first)
    • Showing the date/time you've made an update on a separate line on the article only if you've indeed made an update, and without affecting the order of the articles or the default date shown on the article
    • Outputting pre-defined tags relevant to your page and allow each tag to link to a new search using that tag (you will learn how to disable this in a moment)

The adventurous of you will be wondering “this is all well and good, but what if I want to change the way my news looks? What if there are more fields that I want? What if there is anything else I want to configure?”...

There are a number of pages that you can configure till your heart's content.

Plugins → Configure I18N Special Pages → I18N News → General

Here you can change basic information; the name of your special page type (you can get rid of the I18N for example – I simply put it there to keep it distinct from any other special page types you may have already had), the parent page (where all of your news pages get filed under), default tags and keywords (what metatags would all of your news pages need), the template for the page (does it need an entirely distinct look?) and its menu placement (how is it ordered in the menu – newest first or newest last?).

Plugins → Configure I18N Special Pages → I18N News → Fields

This section is where you can define your fields. The one you will need to change particularly is the 'Category' field – fill it in with all of the relevant categories for your news. You can also tick the 'index' box on any of the possible fields so that when your user uses the search bar, they can also search for information contained in those fields (so if they wanted to search for content by a particular author, they can do so if the 'Author' field is indexed).

Plugins → Configure I18N Special Pages → I18N News → View

Want to style the look of the news article itself? Here you can. I've provided a basic CSS template for you in the 'HTML/PHP code for the header of the page' section and a fairly comprehensive setup for the page itself in the 'HTML/PHP code for the display of a page' section which you can modify as much as you want. Particularly, where it says:

<div class="tags"><strong>Tags</strong>: <?php get_special_tags($slug='i18n-search', $separator=',', $all=false); ?></div>

Change 'i18n-search' to null if you couldn't get the fancy URLs to work, so that your tags have no broken links on them. If you've changed the url (the slug) of your Search page (e.g. 'search' instead of 'i18n-search'), make sure you change this accordingly too.

Plugins → Configure I18N Special Pages → I18N News → Search

If you want to style the look of the listed news entries then here is your ticket. Again, a comprehensive template is provided for you and below it is the CSS for you to tinker with.

Make sure to click 'Save Special Page Type' after making any changes.

Pages → News

Here you can change the slug of the news page (again, if you want to remove the 'i18n' label). If you do, make sure that you re-define the parent of the news page again (in Plugins → Configure I18N Special Pages → I18N News → General) because it defines the parent by the slug, not the page name.
In particular, this page has a number of variables that you can configure which affect the output of the news entries. Just as an example, numWords says how many words or paragraphs of the main content to output if you haven't got a summary, so “30” would mean 30 words, “1p” means one paragraph. Max defines how many items you want per page, HEADER defines the header name of the results, etc...

For more information go to Plugins → Configure I18N Search in your admin panel.

Extra functionality

Here are just a few extra tidbits you may want to know for configuring your special page types for the full effect.

(i) Syntax Highlighter

Editing HTML, CSS and PHP can be difficult without a good text format and highlighter for the various functions. Install the Theme Syntax Highligher plugin to make the HTML in the configuration pages much easier to view and edit.

Note: If your a text-area field is blank when you open the page, don't panic: just click on the area and it should come up with the content with the highlighter in use.

(ii) External Comments

Some news entries deserve to be commented on. If you want to have a news comments box, install the External Comments plugin and configure it according to the instructions given. Then in Plugins → Configure I18N Special Pages → I18N News → View, under 'HTML/PHP code for the display of a page', where you see:

<div class="tags"><strong>Tags</strong>...

Paste this beneath it

<div class="commentsbox"><a name="commentsbox"></a><?php get_external_comments(); ?></div>

Then save the page. Your news should now have the comments box attached to the end of each post.

(iii) Social Network Buttons

There is a plugin for this, but I think that sometimes it is better to just go with the raw HTML when it is simpler. In Plugins → Configure I18N Special Pages → I18N News → View, under 'HTML/PHP code for the display of a page', where you see:

<div class="tags"><strong>Tags</strong>...

You can paste the code from AddThis! beneath it to put your social networking buttons; for example:

<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4f5b39ad5e8d7f7d"></script>
<!-- AddThis Button END -->

If you want them to be on the search results paste it on the 'Search' tab instead of 'View' and modify your links so that instead of saying:

<a class="addthis_button_preferred_1"></a>

They say this:

<a class="addthis_button_preferred_1" href="<?php get_special_field('link','',false); ?>#"></a>

(iv) RSS (Really Simple Syndication)

Updates to your news should be easily accessible and as instantaneous as possible. The use of RSS feeds allows this to happen; if your users subscribe to the news feed, they get alerted immediately of any new changes that you make.

To do so, put the tag 'rss' on your individual article pages under the field 'Tags & Keywords' then save the page. This immediately adds the tag to the news feed, which can be found by placing the following code on the page of your news list:

(% searchrss name:news title:"News" tags:news numWords:30 %)

If you want each new article to automatically be added to the news feed, add the tag to the default tags list in Plugins → Configure I18N Special Pages → I18N News → General and save.

(v) Latest News Widget

Draxeiro of the GetSimple support boards suggested that members also know about how to include a 'Latest News' portion of their articles in their sidebars; something which I surprisingly hadn't touched on. Doing this is actually pretty simple, and simplified even further by the use of Special Pages (which allows you to easily enable/disable this widget per news article).

Assuming that you already have a sidebar set up, all you need is this basic markup to display your widget (really you can insert it anywhere you want on the page!):

<?php
  if(returnPageField(return_page_slug(),'latestnews')!='') {
    get_i18n_search_results(array('tags'=>'_special_news', 'order'=>'created', 'max'=>'5', 'numWords'=>'1p', 'HEADER'=>'Latest News', 'showPaging'=>'0'));
  }
?>

Then in your Special Pages configuration panel, create the following field:

NAME LABEL TYPE DEFAULT VALUE
latestnews Show Latest News Check box on

To display/hide your widget you simply tick the checkbox when editing the news entry's page.

Configuring this widget is the same as configuring any I18N Search Results page. The full list of available settings is shown on the Search Settings page, so look there for the variables that you wish to change. As a hard and fast rule though, if you want to quickly modify the following then just look below:

Excerpt Length Currently shows first paragraph of the news. Change 'numWords'=>'1p' to 'numWords'=>'X to show X number of words, Xp to show X number of paragraphs or 0 to show no excerpt.
Header Currently has header 'Latest News'. Change the 'Latest News' in 'HEADER'=>'Latest News' to whatever you choose to.
Number of entries shown/pagination Currently shows a maximum of 5 entries without pagination. Change '5' in 'max'=>'5' to your choosing and 'showPaging'=>'0' to 'showPaging'=>'1' to show pagination (not recommended for a sidebar).
Show Language Currently shows language of the entry. Insert “ ,'showLanguage'=>'0'” to the end of the current array to remove this feature.
Search Entry Markup If the current markup is really not to your liking and you want to fully customise it, then create a component (any name will do) and insert to the end of the array “ ,'component'=>'componentname'”. You can then configure your component to output the results exactly how you want, similar to how you can with the SEARCH tab of the Special Pages configuration page. Check mvlcek's site for the correct syntax to use for this method.

Furthermore, this has been set up so that the latest news widget is displayed on all your news entries, but is disabled for the particular news article when you untick the 'Latest News?' checkbox. If instead you'd like it to be disabled for all pages by default but enabled when you tick the box, instead use this for the IF statement:

... if(returnPageField(return_page_slug(),'latestnews')=='') ...

If you want to enable/disable this feature for pages that aren't specifically news you can either add the 'latestnews' field to the other Special Page types you have out there, or install I18N Custom Fields and make the 'latestnews' field a universal one for all page types to be enabled/disabled or even hardcode the IF statements for specific pages. For example, if you wanted the ticking of the checkbox to enable the widget but for the widget to be displayed on the main news page regardless, you would use the following IF statement:

... if((returnPageField(return_page_slug(),'latestnews')=='') || (return_page_slug()=='news')) ...

That should cover all that you need to know on the Latest News widget!

Conclusion

As you've probably wagered by now, I love using GetSimple. It is an amazing tool with endless possibilities, proving that OpenSource freeware is a concept to be praised. Hopefully you have seen the benefits of using the i18n plugins, in addition to the benefits of GetSimple in general, and are now provided with the tools to do whatever it is you desire regarding news functionality on GetSimple.

If you have any questions about new functions to add on to news or about how to use the Special Pages plugin in more unique ways, feel free to place a comment below or find me on the GetSimple support community forum. I'll be happy to help. :-)

Special thanks to...

  • mvlcek (creator of i18n and child plugins)
  • ccagle8 (creator of GetSimple CMS)
  • RobA (creator of External Comments plugin)
  • roog (creator of News Manager plugin)
  • dominionit (creator of Dominion Blog/News)
  • alienee2 (fellow Special Pages template developer)
  • sal, andyash and Draxeiro  (re-read the previous articles to find faults)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment