help to creat a widget
-
Hi i’m a newbie in PHP and wordpress,and i try to create a widgets for my theme, using this code who make a box with title and content:
<div id="%1$s" class="box"> <div class="one-col box-top"> <h3 class="box-title">Title</h3> </div> <div class="one-col box-body"> txt & contents her </div> <div class="one-col box-bottom"></div> </div>how can i insert it in the function.php and let it work in my sidebar?
Thanks
-
any idea on how to include the code to be a widget?
ThanksHi,
You can add this code in functions.php file of your theme and call this function from sidebar.php of the theme with required parameters..
Thanks,
Shane G.
i know but the code in the function must to be some thing as this to work :
<?php if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '<div id="sbitem">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>', )); ?>Any help please.
ThanksCouldn’t you just use a text widget?
i need a dynamic widget not manual pls
Consider downloading and installing Otto’s PHP Code Widget.
hi MichaelH,
thanks for the link, but i’m working to creat a website, and i need to let this code:<div id="%1$s" class="box"> <div class="one-col box-top"> <h3 class="box-title">Title</h3> </div> <div class="one-col box-body"> txt & contents her </div> <div class="one-col box-bottom"></div> </div>to be a widget ready, so how can i change it to some thing like this in the function.php :
Exemple<?php if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '<div id="sbitem">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>', )); ?>Thanks for any help.
Guess you could look at how other’s code widgets:
taghaboy:
That code is required to make a widgetized area in your theme, not to build a widget. To do this, try the following:
1. Create a function (say “my_last_posts”)that will display your widget (meaning it will echo the code you mentioned above);2. Register the widget and tell wp that it is going to use your function:
function my_last_posts_init(){ register_sidebar_widget(__('Last Posts'), 'my_last_posts'); }That should be enough for you to find the widget available in your widgets list.
Forgot to mention these 2 functions must be in functions.php or as a plugin in your wp-content/plugins directory.
I’m victim of my bad English, and i will explain again my need, and sorry to be a heavy guest!
I create a theme who work fin, and i add the BOX in the sidebar manually, so in every time i must add this HTML code with some PHP on it to show for example : Recent post, Latest comment, Pages, Category…<div id="id-box" class="box"> <div class="one-col box-top"> <h3 class="box-title">The Title</h3> </div> <div class="one-col box-body"> My PHP code her </div> <div class="one-col box-bottom"></div> </div>so know, i want to upgrade my theme by supporting widget (add any widget from the admin-panel and show it in the sidebar area of my theme), so i create the file function.php (as in other widgetized themes) and i copy this code into-it :
<?php if ( function_exists('register_sidebar') ) register_sidebar(array( 'before_widget' => '<div id="sbitem">', 'after_widget' => '</div>', 'before_title' => '<h2>', 'after_title' => '</h2>', )); ?>but this code dont show the structure of the the box i want as in the HTML code in the top ( <div id=”id-box”…. )!!!
so how can i put my HTML code in the :
befor_widget, after_widget, befor_title, after__titleThanks, and again, i’m so sorry 4 my English.
If I understood what you mean, you just have to replace the strings with the html code you want.
So:
'before_widget' => '<div id="sbitem">',
would be
'before_widget' => '<div id="id-box" class="box"><div class="one-col box-top">',and so on…
that’s what i want Mr Renato.
i hop you show me the rest of the code.
And thanks for all[moderated–bump removed. Please refrain from bumping as per Forum Rules]
What does mean bump!!!
Any idea or Tutorial to convert the code to some thing befor-widget…
Thanks
The topic ‘help to creat a widget’ is closed to new replies.