Skip to content

Create new editable areas or editable blocks

Robert Isoski edited this page Mar 30, 2020 · 5 revisions

Difference between editable blocks and editable areas

  • Blocks = static editable areas
  • Regular editable areas = dynamic editable areas

WonderCMS 3.0.0 and above

How to display regular (dynamic) editable areas

<?= $Wcms->page('content')?>

How to display editable blocks (static)

<?= $Wcms->block('yourEditableBlockName')?>

Creating regular (dynamic) editable areas for a specific page with a plugin

  1. Download the additional contents plugin, unzip and upload to your plugins folder.
  2. A green "+" will appear once logged in, enabling you to create new editable areas easily and additionally hide/show them for each page.

Creating (static) editable blocks with functions.php

  1. Create functions.php file in your theme folder.
  2. Paste the following code into functions.php - newEditableArea can be renamed to anything else.
<?php
	function newEditableArea() {
		global $Wcms;

		// Check if the newEditableArea area is already exists, if not, create it
		if (empty($Wcms->get('blocks','newEditableArea'))) {
			$Wcms->set('blocks','newEditableArea', 'content', 'Your content here.');
		}

		// Fetch the value of the newEditableArea from database
		$value = $Wcms->get('blocks','newEditableArea','content');

		// If value is empty, let's put something in it by default
		if (empty($value)) {
			$value = 'Empty content';
		}
		if ($Wcms->loggedIn) {
			// If logged in, return block in editable mode
			return $Wcms->block('newEditableArea');
		}

		// If not logged in, return block in non-editable mode
		return $value;
	}
?>
  1. Save functions.php and the changes made.
  2. Open theme.php and paste <?=newEditableArea()?> anywhere you wish to display this new editable area.
  3. Visit your website.
  4. Once you've visited your website, the functions files will be called and your editable area is created.
  5. Remove <?=newEditableArea()?> from theme.php.
  6. Final step: <?= $Wcms->block('newEditableArea')?> anywhere in your theme.php to display your newly created editable area.

WonderCMS 2.7.0 and previous versions

How to display regular (dynamic) editable areas

<?=wCMS::page('content')?>

How to display editable blocks (static)

<?=wCMS::block('yourEditableBlockName')?>

Creating regular (dynamic) editable areas for a specific page with a plugin

  1. Download the additional contents plugin, unzip and upload to your plugins folder.
  2. A green "+" will appear once logged in, enabling you to create new editable areas easily and additionally hide/show them for each page.

Creating (static) editable blocks with functions.php

  1. Create functions.php file in your theme folder.
  2. Paste the following code into functions.php - newEditableArea can be renamed to anything else.
<?php
	function newEditableArea() {
		// Check if the newEditableArea area is already exists, if not, create it
		if (empty(wCMS::get('blocks','newEditableArea'))) {
			wCMS::set('blocks','newEditableArea', 'content', 'Your content here.');
		}

		// Fetch the value of the newEditableArea from database
		$value = wCMS::get('blocks','newEditableArea','content');

		// If value is empty, let's put something in it by default
		if (empty($value)) {
			$value = 'Empty content';
		}
		if (wCMS::$loggedIn) {
			// If logged in, return block in editable mode
			return wCMS::block('newEditableArea');
		}

		// If not logged in, return block in non-editable mode
		return $value;
	}
?>
  1. Save functions.php and the changes made.
  2. Open theme.php and paste <?=newEditableArea()?> anywhere you wish to display this new editable area.
  • You have now successfully created your first editable block called newEditableArea with the help of a function.
  • Use <?=wCMS::block('newEditableArea')?> anywhere in your theme to display your static block.
  • You can remove the newEditableArea() function from functions.php since you don't need it any more and your editable block is already created.
Clone this wiki locally