• Hi,

    Not really a support request but more some code that can be used to enhance the plugin

    add the following function

    function return_template_sidebars() {
        global $post;
        $sidebarsArr = array();
        $template = file_get_contents( get_template_directory() . DIRECTORY_SEPARATOR .  $post->page_template );
        if ( $template != false ) {
            preg_match( '|Sidebars:(.*)$|mi', $template, $matches );
            if (!empty($matches[1])) {
                $tempArr = explode(",", $matches[1]);
            }
            foreach ($tempArr as $temp) {
                $sidebarsArr[] = trim($temp);
            }
        }
        return $sidebarsArr;
    }

    Then modify i123_widgets_custom_fields_controllbox by adding

    $sidebarsArray = return_template_sidebars();

    just before
    foreach($wp_registered_sidebars as $key => $value) {

    and
    if (!in_array($value['id'], $sidebarsArray, false)) continue;

    just before
    <div class="i123_widgets_formline">

    This then allows you to add
    * Sidebars: sidebar-1, sidebar-2
    into your template files which means you limit the sidebars shown based on the template being used to display the page.

    It needs a little more code writing so that it will pick up default templates but the basics are there

    https://www.ads-software.com/extend/plugins/per-page-widgets/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Per page widget works fine for me but not at the post page.

    Is there a way to make Per Page Widget also work at the post page?

    Jeroen

    Per page widget works fine for me but not at the post page.

    Is there a way to make Per Page Widget also work at the post page?

    Jeroen

    The widgets do not show up on my pages.

    modify the function i123_widgets_custom_fields_add() and per page widgets will work with custom post types

    function i123_widgets_custom_fields_add() {
    i123_widgets_admin_init();
    add_meta_box( 'i123_widgets_custom_fields', __('Per Page Widgets', 'i123_widgets'), 'i123_widgets_custom_fields_controllbox', 'post', 'side', 'high' );
    add_meta_box( 'i123_widgets_custom_fields', __('Per Page Widgets', 'i123_widgets'), 'i123_widgets_custom_fields_controllbox', 'page', 'side', 'high' );
    $args=array(
    'public' => true,
    '_builtin' => false
    );
    $operator = "and"; //'and or 'or'
    $output = "names"; //names or objects - names is default
    $post_types = get_post_types($args,$output,$operator);
    foreach($post_types as $post_type) {
    add_meta_box( 'i123_widgets_custom_fields', __('Per Page Widgets', 'i123_widgets'), 'i123_widgets_custom_fields_controllbox', $post_type, 'side', 'high' );
    }
    }
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Per Page Widgets’ is closed to new replies.