PHP
If you're a coder probably you know what PHP is. If you're not, PHP is a server-side scripting language designed for web development but also used as a general-purpose programming language. Originally created by Rasmus Lerdorf in 1994, the PHP reference implementation is now produced by The PHP Group. PHP originally stood for Personal Home Page, but it now stands for the recursive initialism PHP: Hypertext Preprocessor.
PHP Functions
You can use either wp_bannerize_pro()
or get_wp_bannerize_pro()
to display your banner. The key difference is that get_wp_bannerize_pro()
returns the HTML output for the banner, for example:
<?php
// Display a single banner
if( function_exists( 'wp_bannerize_pro' ) ) {
echo get_wp_bannerize_pro( array( 'id' => '156' ) );
}
Probably you want to display a banner without using echo
and then get_wp_bannerize_pro()
. In this case, you can use wp_bannerize_pro()
:
<?php
// Display a single banner
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'id' => '156' ) );
}
Important
A good practice is to use if( function_exists( 'wp_bannerize_pro' ) )
to check if the function exists before calling it.
Where to put the code
You can put the code in your theme files, for example, in the header.php
file, or in a custom template file. You can also use the code in a widget or in a shortcode.
Params
Name | Default | Description |
---|---|---|
id | null | ID or slug comma separate (default null ) |
categories | [] | Banner categories slug or id (default '' ) - deprecated from version 1.8.0 |
campaigns | [] | Banner campaigns slug or id (default '' ) |
post_categories | [] | Any string, int or array of string, id. (default '' ) |
order | "DESC" | Order "ASC" or "DESC" |
orderby | "menu_order" | Order by or 'impressions' , 'clicks' , 'ctr' or 'random' . (default 'menu_order' ) |
rank_seed | true | Set to true to give some chances to the banners to be showed when use Impressions, Click or CTR |
numbers | 10 | Max numbers of banners (default 10 ) |
layout | vertical | Banners layout, "horizontal" or "vertical" (default 'vertical' ) |
Important
The attribute categories
is deprecated. Use campaigns
instead.
Examples
Below are some examples of how to display banners using PHP.
Display a single banner
<?php
// Display a single banner
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'id' => array( 156, 'my-banner-slug', 158 ) ) );wp_bannerize_pro( array( 'id' => '156' ) );
}
Display a set of banners by a comma separated string of banner IDs
<?php
// Display a set of banners by a comma separated string of banner IDs
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'id' => '156,157,158' ) );
}
Display a set of banners by an array of banner IDs
<?php
// Display a set of banners by an array of banner IDs
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'id' => array( 156, 157, 158 ) ) );
}
Display a set of banners by mixed id and slug values
<?php
// Display a set of banners by mixed id and slug values
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( wp_bannerize_pro( array( 'id' => array( 156, 'my-banner-slug', 158 ) ) );
}
Display all banners from banner category "sidebar" in random order
<?php
// Display all banners from banner category "sidebar" in random order
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'categories' => 'sidebar', 'orderby' => 'rand' ) );
}
Display all banners from banner category "sidebar" in random order with a limit of 3 banners
<?php
// Display all banners from banner category "sidebar" in random order with a limit of 3 banners
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'categories' => 'sidebar', 'orderby' => 'random', 'numbers' => 3 ) );
}
Display banners from banner category "sidebar" and post categories news and events
<?php
// Display banners from banner category "sidebar" and post categories news and events
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'categories' => 'sidebar', 'post_categories' => 'news,events' ) );
}
Or... as array of slug values
<?php
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'categories' => 'sidebar', 'post_categories' => array( 'news', 'events' ) ) );
}
Or... as array of Title values
<?php
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'categories' => 'sidebar', 'post_categories' => array( 'News', 'Events' ) ) );
}
Or... as array of ids
<?php
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( array( 'categories' => 'sidebar', 'post_categories' => array( 1, 2 ) ) );
}
Display a set of banners only for mobile device
<?php
// Display a set of banners only for mobile device
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( [ 'mobile' => true, 'id' => [156,157,158] ] );
}
Display a set of banners only for desktop device
<?php
// Display a set of banners only for desktop device
if( function_exists( 'wp_bannerize_pro' ) ) {
wp_bannerize_pro( [ 'desktop' => true, 'id' => [156,157,158] ] );
}