Wordpress - display widget - wordpress

I'm creating a custom theme and in my contact page i want to add a widget to display google maps map throught Wp Google Map plugin but i can't show the map in my page.
In my functions.php i have this:
function arphabet_widgets_init() {
register_sidebar(array(
'name' => 'My_Widgtet_Area',
'id' => 'map-area',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="rounded">',
'after_title' => '</h2>',
));
}
In my html file:
<?php
$map = get_page_by_title( 'Mapa' );
echo $map->post_content;
?>
In my page content:
[wpgmza id="1"]
How can i display or associate the widget to my page?
Thank's

You can add the map directly using the given shortcode or you can add the shortcode in the widget and add the widget in page.
To add the map directly in the page using shortcode
echo do_shortcode('[wpgmza id="1"]');
To add widget in the page
dynamic_sidebar('map-area');
Hope it helps...
Please ask if you have any doubts.

Related

How to create a widgetized sidebar for a theme with no sidebar?

Please could someone show me how to do this? My theme (Fable) does not have a built-in sidebar and I need one for my homepage.
Many thanks!
Create a child theme.
Create a file sidebar.php.
In your sidebar.php-file you have to use at least the following function: dynamic_sidebar()
Furthermore in your functions.php file of your child Theme you must use the following functions: register_sidebar()
Include the sidebar in your child theme (most probably in the overwritten index.php-file)
Style the sidebar to integrate it with your Theme properly.
For further documentation see the WordPress Codex:
https://codex.wordpress.org/Child_Themes
https://codex.wordpress.org/Function_Reference/dynamic_sidebar
https://codex.wordpress.org/Function_Reference/register_sidebar
Put this in your functions.php file:
<?php
// Declare sidebar widget zone
register_sidebars( 1,
array(
'name' => 'My Widget Area',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h3 class="widgettitle">',
'after_title' => '</h3>'
)
);
?>
Then put this in the place in your theme where you want the widget area to appear:
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('My Widget Area')) : else : ?><?php endif; ?>

activate plugins on custom theme

I'm new to Wordpress and just created my first template.
In the functions.php I have put the following code, that function what I understand should call the plugins from the plugins directory:
if (function_exists('register_sidebar')) {
register_sidebar(array(
'name' => 'Widgetized Area',
'id' => 'widgetized-area',
'description' => '',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));
}
I do see all the plugins, and in the widget screen I also see the 'widgets' screen and it allows me to drag widgets into the working area.
The website itself displays the plugin's html but neither js nor css is working.
What am I missing?
Above code that you have added in your functions.php is to register sidebar not to call any plugin. It do not have any connection to plugin.
You can call sidebar you added in template as follow:
if ( is_active_sidebar( 'widgetized-area' ) ) {
dynamic_sidebar( 'widgetized-area' );
}

wordpress plugin installation

I am learning wordpress. Now I want to install a simple photo gallery plugin. For that I have downloaded plugin from internet. Now how to integrate that so that I can find from the front-end in a particular position.
Thank you.
Your theme should have specific areas to put the plugins in.
If not You should open the php file of the template that you want to display the plugin in and add this code:
if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Your plugin name') ) :
endif;
Now, open your functions.php and add this:
if ( function_exists('register_sidebar') ) {
register_sidebar( array(
'name' => 'Your plugin name',
'id' => 'login-widget',
'before_widget' => '<section class="login-widget">',
'after_widget' => '</section>',
'before_title' => '<span class="widget-title">',
'after_title' => '</span>')
);
}
after you are done with that, you can go to your administrator page, click on Appearance -> Widgets and then drag the plugin name from the list to the dock named "Your plugin name"

Adding widget area to functions.php causes blank screen after posting anything in admin

I'm following multiple tutorials that all tell me to put this into my functions.php to add a widget area:
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'before_widget' => '',
'after_widget' => '',
'before_title' => '<div class="title">',
'after_title' => '</div>',
));
?>
Once I upload that file and try to change anything, like post or edit a post I get a white screen directly after hitting publish or any other action button.
Is there something wrong with that code? Or am I missing something when it comes to adding widget areas to my template?
Wordpress doesn't like blank lines on the functions.php page..

How to display my wordpress widget programmatically?

I need to display my custom made widget in WP page based custom page template programmatically.
This is the scenario:
I created page based on custom page template called "product" now I need in its sidebar display my custom made widget. I need this side bar to be totally different from other pages this is why I want to display it programmatically.
I tried to use the_widget() function but I think it works only with built in widgets and also I don't know how to pass parameters registered with register_sidebar function to it, because it seems it doesn't use them by default.
Actually I used this : the_widget('WP_Widget_Search') to test it and widget was there but it ignored theme settings, I mean settings in function.php :
register_sidebar( array(
'name' => 'Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<h3>',
'after_title' => '</h3><div class="padder">'
) );
So as I said I don't know if it works with custom made widgets (created in plugins) because I don't know how to pass widget name there and params. How to do that?
Dynamically create a dynamic instance of the widget using the_widget(), eg:
<div id="xxx" class="widget-area" role="complementary">
<div id="sidebar-dyn">
<?php the_widget( 'WP_Widget_Recent_Posts' ); ?>
</div>
</div>
Why the need to include custom widget programatically. I mean you can simply create another sidebar that is shown only on your custom page template "product"
Further as you need to do it for your custom page, you don't even need to check for any condition. Simply put this code in your "prdouct" page template file anywhere ( where you would like to display your sidebar".
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Product Sidebar')) ;?>
And simply drag your widget to this sidebar from admin panel.
If the widget has a shortcode, call it using this:
<?php echo do_shortcode( $content ) ?>
you're question isn't exactly clear to me, but what i am gathering is that
1. you need to register your widget and
2. you need for it to ONLY show on the product page.
to register, place this in functions.php (you may already have the first line in your functions file):
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array(
'name'=> 'Product Sidebar',
'before_widget' => '<div id="%1$s" class="widget %2$s">',
'after_widget' => '</div></div>',
'before_title' => '<h3>',
'after_title' => '</h3><div class="padder">'
));
?>
this would be the code to include in sidebar.php to display the above only on the page called "Product".
<?php if (is_page('Product')) ;?>
<?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Product Sidebar')) ;?>
<?php endif; ?>

Resources