[SOLVED] How to add a new subside only for one page?

Post Reply
wdq
Posts: 9
Joined: Fri Dec 02, 2016 11:44 pm

[SOLVED] How to add a new subside only for one page?

Post by wdq »

my question si really simple and because the code changed a lot i want to know how to add a subside that will not appear on all pages and when you make a new theme what i shoud keep in the css file so that the settings menu still work because i saw that if you change some irelevant things in the css style stops the menu from apearing ?
Last edited by wdq on Thu Dec 08, 2016 6:17 am, edited 1 time in total.
yassineaddi
Posts: 10
Joined: Wed Nov 09, 2016 2:10 pm

Re: how to add a new subside only for one page

Post by yassineaddi »

Hello, wdq

As you said, it's very simple to add custom content, in your theme.php of the theme you're designing, you can do a simple "if" condition and display your custom content. Here is a simple example:

In the

Code: Select all

theme.php
right after the existing subside. I will add the following code:

Code: Select all

<?php if (wCMS::$_currentPage == 'my special page'): ?>
    <div class="marginTop20 blueBackground padding20 rounded5">
        <h4>Special Subside!</h4>
        <p>This is a special subside that will appear only on a specific page!</p>
    </div>
<?php endif ?>
Now, if you access

Code: Select all

http://yourwebsite.com/my-special-page
you'll notice that a new subside has been added! (I'm testing on the official theme).

Thanks to it's core that has been built using OOP (oriented object programming) you can access any property or method from the core (index.php).

If you need to separate things, you can just include this portion of code from another file, like so:
In theme.php replace what I've wrote earlier with

Code: Select all

<?php include INC_ROOT . '/themes/' . $theme . '/special-subside.php' ?>
And in the same folder as the theme.php create a file called special-subside.php with the following code: (same code as earlier)

Code: Select all

<?php if (wCMS::$_currentPage == 'my special page'): ?>
    <div class="marginTop20 blueBackground padding20 rounded5">
        <h4>Special Subside!</h4>
        <p>This is a special subside that will appear only on a specific page!</p>
    </div>
<?php endif ?>
And you'll get the same results.

Also, there is another way, is to make a plugin that will automates this process by following those steps:

1. Create a new plugin folder inside plugins/ directory and call it something like content_changer and add a file into this created directory and call it content_changer.php and then put the following code inside it:

Code: Select all

<?php
defined('INC_ROOT') OR die('Direct access is not allowed.');

wCMS::addListener('extracted', 'addSpecialSubside');

function addSpecialSubside ($args) {
    $myCode = '<h4>Special Subside!</h4><p>This is a special subside that will appear only on a specific page!</p>';
    if (wCMS::$_currentPage == 'my special page') {
        $args[0]['specialSubside'] = $myCode;
    }
    return $args;
}
and then in the theme.php after the already existing subside:

Code: Select all

<?php if (isset($specialSubside)): ?>
    <?=$specialSubside?>
<?php endif ?>
And that's it!

If you need to make it editable, then you need to modify your own database by adding a key that the script will recognize on edit.

Now for the style.css it doesn't actually matter you can remove the full file and the navigation will still works fine. Just DON'T edit the css and javascript code in the core file (index.php) unless you knwo what you're doing even if it's not recommended as you can simply override the settings menu styles code. which is much easier and stable.

Let me know if there are any other questions!

Once again keep in mind that WonderCMS is aimed to be as simple as possible so that expert and especially starter developers can easily edit/extend it's core to do many tasks.
Post Reply