Skip to content

Instantly share code, notes, and snippets.

@lokothodida
Last active March 24, 2019 14:40
Show Gist options
  • Save lokothodida/9ffccc7f5afa6ad7aa64 to your computer and use it in GitHub Desktop.
Save lokothodida/9ffccc7f5afa6ad7aa64 to your computer and use it in GitHub Desktop.
GetSimple Tutorial for creating a blog with the I18N plugin(s)

GetSimple Tutorial: Creating a blog with the I18N plugin(s)

Ever wanted to have a complete blogging module for GetSimple? Did you know that such a feat is achievable through the use of a number of GetSimple plugins? Look no further than this tutorial in order to discover how to construct such a module yourself!

Plugins that you need

Files that you need

First of all, download the latest version of these plugins and unzip them to your web server. Then download the i18n Blog file and unzip it to the root directory of your GetSimple installation.

Log in to your GetSimple admin panel and go to Themes → Edit Components. Create the following components:

Component: blog-functions

<?php
/* Credit to ccagle8 for the original function(s); edited by lokothodida */
function get_author_username($blogusername) {
    echo return_author_username($blogusername);
}

function return_author_username($blogusername) {
    return find_author($blogusername)->authoruser;
}

function get_author_firstname($blogusername) {
    echo return_author_firstname($blogusername);
}

function return_author_firstname($blogusername) {
    return find_author($blogusername)->authorfirst;
}

function get_author_lastname($blogusername) {
    echo return_author_lastname($blogusername);
}

function return_author_lastname($blogusername) {
    return find_author($blogusername)->authorlast;
}

function get_author_avatar($blogusername) {
    echo return_author_avatar($blogusername);
}

function return_author_avatar($blogusername) {
    return find_author($blogusername)->authoravatar;
}

function get_author_about($blogusername) {
    echo return_author_about($blogusername);
}

function return_author_about($blogusername) {
    return find_author($blogusername)->aboutauthor;
}

function get_author_email($blogusername) {
    echo return_author_email($blogusername);
}

function return_author_email($blogusername) {
    return find_author($blogusername)->authoremail;
}

function get_author_snippet($blogusername) {
    echo return_author_snippet($blogusername);
}

function return_author_snippet($blogusername) {
    return find_author($blogusername)->authorsnippet;
}

function get_author_profile($blogusername) {
    $avatar_url = return_author_avatar($blogusername);

    if ($avatar_url != '' && (return_special_field('showavatar') == '')) {
        echo '<p align="center"><a href="' . find_url($blogusername,'') . '">Show Profile</a></p>';
    } else {
        echo '<a href="'. find_url($blogusername, '') . '"><p align="center"><img src="' . $avatar_url . '"/></p></a>';
    }
}

/**
  * @access private
  */
function find_author($blogusername) {
    static $authors = [];

    if (isset($authors[$blogusername])) {
        return $authors[$blogusername];
    } elseif (file_exists($file = GSDATAPAGESPATH . $blogusername .'.xml')) {
        return $authors[$blogusername] = getXML($file);
    } else {
        return author_with_default_properties();
    }
}

/**
  * @access private
  */
function author_with_default_properties() {
    $author = new stdClass();
    $author->authoruser = '';
    $author->authorfirst = '';
    $author->authorlast = '';
    $author->authoravatar = '';
    $author->aboutauthor = '';
    $author->authoremail = '';
    $author->authorsnippet = '';

    return $author;
}
?>

Component: blog-latestnews

<a href="<?php echo $item->link; ?>"><?php echo htmlspecialchars($item->title, ENT_NOQUOTES); ?></a>

Now go to Plugins → Configure I18N Special Pages and click 'I18N Author' then 'Save Special Page Type'.

While still in the configuration of I18N Special Pages, click 'I18N Blog'. Under the 'FIELD' tab, change the content of the 'Category' field drop-down menu to have the categories that you want, then click 'Save Special Page Type'. You are now ready to add authors and start blogging!

Creating Authors

Go to Pages → Create New Special Page → I18N Authors and fill in the fields with the relevant content. Make sure that in the slug field you have the desired username of your author. The 'snippet' field is there for you to define any author-specific page snippets for the blog entries that are published. Save the page and you've got an author.

Publishing Blog Entries

Go to Pages → Create New Special Page → I18N Blog and once again fill in the relevant content. This time, under the 'Username' field, make sure that it exactly matches the username you defined for the author who is publishing it. You have the option to:

  • Display a sidebar/snippets – these show some typical blog features, such as a search bar, share links, other recent articles, etc...this also includes the author-specific snippets that you defined just before.
  • Display author avatar – basically choose whether to show the avatar or not.
  • Display 'About Author' – shows a piece at the end of the article which has information about the author – you defined this information in the 'About Author' field of the author's page.

Save the page, and you've published the article! For you to keep blogging, simply create new blog entries whilst ensuring that the 'Username' field matches the username of the publisher. :)

Important note: Fancy URLs need to be enabled for your tag links to work on your blog entry page(s).


Extras

Removing the 'i18n' from the pages

Simply edit the name of the Special Page type to remove it from the page type name. As for the Author, Blog and Search pages, simply edit the slug/url of those pages, but ensure that you remove the 'i18n' prefix from the fields on following pages too:

  • Plugins → Configure I18N Special Pages → (I18N) Blog → VIEW
  • Plugins → Configure I18N Special Pages → (I18N) Blog → SEARCH

Use CTRL+F to find the 'i18n' prefix, delete it then save the page. This ensures that your tags will work.

Adding functions for new fields

If you create new fields for your authors to fill, you may want to call upon those fields on the published blog entry. If you create a field with the name fieldname, paste the following in the php coding of the blog-functions component:

function get_function_name($blogusername) {
    echo return_function_name($blogusername);
}

function return_function_name($blogusername) {
    return find_author($blogusername)->fieldname;
}

Replacing fieldname with the exact name of the field you've created, and function_name with an appropriate name for your new function. To either get or return the function, use one of the following code(s):

<?php get_function_name($blogusername); ?>

or

<?php return_function_name($blogusername); ?>

In your code for the blog entry (under the VIEW or SEARCH tab).

Integration with Multi-Users plugin

jay_m from the support forum pointed out that a slight change in the code can make this script more compatible with the Multi-User plugin, one that enables accounts to be made that access the back end of the site. Simply change the $blogusername variable to:

$blogusername = return_special_field('user', '', false);

And the script will look for the username of whomever created the page without you needing to define this yourself every time. You still must ensure that an 'author' page is created with a slug that matches the username of the content creator.


Special thanks to...

  • mvlcek (creator of i18n and child plugins)
  • ccagle8 (creator of GetSimple CMS)
  • jay_m (tested tutorial and provided accomodation for Multi-Users)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment