• I like to create page templates with predefined boxes to achieve the same look/feel. This would help for ad-placements within pages.

Viewing 15 replies - 1 through 15 (of 17 total)
  • I’d suggest either creating a template that calls child pages using get_posts for each of your boxes. Or create a widget-capable page template so that users can use the Text widget for their ads. The rest of the styling is just down to CSS.

    Thread Starter Old Cow

    (@old-cow)

    Thanks esmi, I know how to create page-, blog-, category- templates, but how can I create a widget-capable page template?

    In exactly the same way that you create a widget-ready sidebar. You use an

    <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar()) : ?>
    <?php endif; ?>

    block to define a widget area within the template.

    Thread Starter Old Cow

    (@old-cow)

    Hi esmi,
    I assume, I have first to register the sidebar in function.php
    register_sidebar(array(‘name’=>’dynamic_sidebar’,));
    and then place your code into the template or page, where the widget should be displayed?

    Yes – that’s it in a nutshell. If you want to give them different names so that you can identify the various boxes in the Admin area, you can use something like:

    if (function_exists('register_sidebar')) {
    	register_sidebar(array(
    		'name'=> 'Box 1',
    		'id' => 'b1',
    		'before_widget' => '<div id="%1$s" class="widget_wrapper"><div class="widget_box">',
    		'after_widget' => '</div></div>',
    
    	));
    	register_sidebar(array(
    		'name'=> 'Box 2',
    		'id' => 'b2',
    		'before_widget' => '<div id="%1$s" class="widget_wrapper"><div class="widget_box">',
    		'after_widget' => '</div></div>',
    
    	));
    
    }
    Thread Starter Old Cow

    (@old-cow)

    Thanks, I have already a couple of sidebars registered. It would make sense to have them systematically labeled for later identification.

    Thread Starter Old Cow

    (@old-cow)

    The widget boxes I created are now displayed in the admin area.

    How can I integrate them into specific pages? Do I have to insert your code:

    <?php if (function_exists(‘dynamic_sidebar’) && dynamic_sidebar()) : ?><?php endif; ?>

    into the page-template directly or can I do it while I’m editing a page?

    It has to be within a template, so you may need to create 1 or more custom templates

    Thread Starter Old Cow

    (@old-cow)

    Thanks, I thought so.

    I made whats mentioned above. I have a template which includes:

    <?php if (function_exists(‘dynamic_sidebar’) && dynamic_sidebar()): ?>

    <?php endif; ?>

    How do I inlude in the template the code to open an RSS feed in that box?

    Also, I have a Box 1 which I want to be below the contents area, and a sidebar. The contents of the sidebar get duplicated in the new Box 1

    How do I include in the template the code to open an RSS feed in that box?

    Have you tried just dropping the RSS widget into it?

    The contents of the sidebar get duplicated in the new Box 1

    Check that you haven’t replicated a name or id in the register_sidebar function in functions.php

    Thread Starter Old Cow

    (@old-cow)

    I’m still not there yet. The widget boxes I created are displayed in the admin area.

    I created a page_box template and added
    <?php if (function_exists(‘dynamic_sidebar’) && dynamic_sidebar()) : ?>
    <?php endif; ?>
    near the end of <div id=”content”>; all widgets show up.

    When I insert
    <?php if (function_exists(‘Box 1’) && Box 1()) : ?>
    <?php endif; ?>
    I get an error message.

    Do I have to create sidebar_box.php and have to include
    <?php include(TEMPLATEPATH.”/sidebar_box.php”);?>
    into the page_box template near the end of <div id=”content”>;?

    Try:

    <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Box 1')) : ?>
    <?php endif; ?>
    Thread Starter Old Cow

    (@old-cow)

    Thanks, it works!

    In case, I would like to show Box 1 and Box 2 on one page, should I add the code for Box 2 under the code of Box 1 or do I have to combine both boxes in one function?

Viewing 15 replies - 1 through 15 (of 17 total)
  • The topic ‘How can I create predefined boxes on pages?’ is closed to new replies.