Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Montezuma Theme »

How to: Any PHP Anywhere

Prev Previous Post   Next Post Next
Old Jan 25, 2013, 03:02 PM
367 posts · Oct 2012
Plugin How to: Any PHP Anywhere

Out of the box, Montezuma allows a limited set of PHP code which serves the needs of most users. However, if you need other code, with two fantastic plugins, you can easily use any PHP code in any template or subtemplate.

First, here's an important concept. With Montezuma, when you hear the term sidebar, also think inside, above, and below your content margins. Montezuma not only allows unlimited widgets in your sidebars, you can have sidebars anywhere, such as in your header, footer, and even in the content area of a template.

PHP Code Widget Plugin

The PHP Code Widget Plugin, allows any PHP code be executed in a sidebar.

For this example, we'll use some PHP code that's not on the limited list, and we'll use it in the content area of the main template, like is done here to make the random images at the top of each page.
  1. In main template, just below the opening div tag for the content area, we insert:

    PHP Code:
    <?php dynamic_sidebar'image-gallery-0' ); ?>
    This automatically created a new sidebar in the widgets area named "image-gallery-0" .

  2. In the widget area, we drag the PHP Code widget to the image-gallery sidebars and insert the PHP code into the PHP Code widget named image-gallery-0.

Code Snippets Plugin

If you're going to repeat code and want to follow Don't Repeat Yourself principles (which make changes much easier later), there's another great PHP plugin called Code Snippets Plugin. It allows you to add callable PHP code to your site, without modifying any of your wp or theme files.

I put all the code to make the random images into a snippet, then, in the PHP sidebar, just called the function. This way, if I change something, I only have to edit the snippet, and it will get changed everywhere it's used.

It's a good idea to prefix all your custom function and global variable names with something like:
PHP Code:
so as not to conflict with any wp or theme PHP code.

If you're putting variables into your snippets, and calling them later, you may also have to use the global construct to access them.

Happy coding!

Update: Here's an example from Juggledad using a different php plugin "exec php".

Last edited by jerryc; Mar 26, 2013 at 09:08 AM. Reason: Clarification

All times are GMT -6. The time now is 05:11 PM.

Powered by vBulletin® Copyright ©2000 - 2022, Jelsoft Enterprises Ltd.