Skip to content

Get data from database

robiso edited this page Jul 23, 2017 · 12 revisions

How to get page data from database.js

Getting page data using the wCMS get function wCMS::get('pages', 'PAGENAME')->PARAM;

  • PAGENAME - actual page name of the page you want to get data from
  • PARAM - page parameter. Available PARAMs for pages:
    • content
    • title
    • description
    • keywords
    • other PARAMs available with plugins such as additional contents

- Examples A - get specific/static page content (editing of theme.php required)

Example A1: Get the content for page about from database.js

<?php echo wCMS::get('pages', 'about')->content; ?>

Example A2: Get title for page about

<?php echo wCMS::get('pages', 'about')->title; ?>

Example A3: Get keywords for page about

<?php echo wCMS::get('pages', 'about')->keywords; ?>

Example A4: Get description for page about

<?php echo wCMS::get('pages', 'about')->description; ?>

- Examples B - get dynamic page content (editing of theme.php required)

Example B1: Get content for current page from database.js

<?php echo wCMS::page('content'); ?>

Example B2: Get current page title

<?php echo wCMS::page('title'); ?>

Example B3: Get current page keywords

<?php echo wCMS::page('keywords'); ?>

Example B4: Get current page description

<?php echo wCMS::page('description'); ?>

How to get other data from database.js

Getting other data using the wCMS get function wCMS::get('config', 'PARAM'); (notice how the syntax is even easier here than fetching page data shown above).

  • Available PARAMs for config
    • dbVersion (returns database version)
    • siteTitle (returns main website title)
    • theme (returns current chosen theme)
    • defaultPage (returns the default home page)
    • login (returns the default login URL)
    • password (returns a hashed password)
    • menuItems (returns menu items)

- Examples C - get config data (editing of theme.php required)

Example C1: Get database version from database.js

<?php echo wCMS::get('config', 'dbVersion'); ?>

Example C2: Get main website title

<?php echo wCMS::get('config', 'siteTitle'); ?>

Example C3: Get theme name

<?php echo wCMS::get('config', 'theme'); ?>

Example C4: Get default page name

<?php echo wCMS::get('config', 'defaultPage'); ?>
Clone this wiki locally