Connect with us

Tips & Tricks

Creating a custom widget

Published

on

Today let’s learn a simple quick trick on how to create a custom widget. For my example I will show you how I created my Showcase widget located in the middle, to the right of the posts.

First under your functions.php file type in the following:

<?php // Custom Widget
function MyCustomWidget() { ?>
<li class="widget">
    <h2 class="heading">Latest Showcase</h2>
        <ul>
        	<?php include(TEMPLATEPATH . '/includes/showcase.php'); ?>
        </ul>
</li>

<?php }

register_sidebar_widget('The Custom Widget for Showcase', 'MyCustomWidget'); ?>
  • Always make sure your code is between the <?php and ?> for it to work.
  • Once we call the function, the rest is assuming html code that you may or may not need.
  • For instance, you may just put in a picture and call it a day. But my code starts with <li< because my sidebar’s start and end with <ul<.
  • Any way, once your done, just set the final “register_sidebar_widget('the widget title', 'the name of the function');

That’s it! Now you have a custom widget with what ever you want!

Continue Reading
4 Comments

4 Comments

  1. Pingback: WPStart.org » Blog Archive » WordPress links week 3 - 2009

  2. Alex

    February 13, 2009 at 11:40 pm

    Thank You! A Lot!

    This really helped me!

    BTW How did you make the archives widget to show the dates separately into two columns?

    Thank you.

    • frosty

      February 14, 2009 at 8:59 am

      No problem, I will write up a post on that, check back or subscribe. Thanks Alex.

  3. Glenn

    March 19, 2009 at 4:51 pm

    Austin,

    I just found this post while checking out my ad. You might want to try this little widget with Widgetifyr.com and see what added features it gives you. In the instant version you’d get all the theme complaint pre and post calls. You can all the nice control panel stuff like a title and description.

    I was thinking about just doing it for you and pasting it here, but I wasn’t sure how code would be translated in a comment.

    Thanks
    Glenn
    Widgetifyr.com

You must be logged in to post a comment Login

Leave a Reply

Tips & Tricks

Remove spaces when echoing the_title

Ever wanted to print or echo the WordPress title attribute without spaces?

Published

on

This little trick can be useful for calling custom functions and printing the title with out spaces for W3C compatibility. I used this trick in a new theme called Galleria, which will be out for public download in the coming days.

Using this comes in handy for a delicious text link:

<?php $title = get_the_title(); ?>
<a href="http://del.icio.us/post?url=<?php echo $title; ?>&amp;<?php echo str_replace(" ", "%20", $title); ?>">
Bookmark This (<?php echo $title; ?>)</a>

What I am doing is calling $title = get_the_title(); and using str_replace(" ", "%20", $title); to replace empty spaces with a %20, which is used in URL encoding empty spaces.

Alternatively you can use a dash or underscore.

Thanks to Jason Boyle for his adaption.

Continue Reading

Tips & Tricks

Display the_excerpt only if there is text

Have you ever wanted to display the excerpt only if you write one? A simple couple lines of code can display the_excerpt any where you like.

Published

on

In my new theme, I am using this coded trick to display the excerpt on a single post only if I’ve got text inside. Usually if you use the_excerpt and you don’t have one, it will fake one for you.

This is not something that I wanted to do on the single post page. So I used the following code to check if the excerpt existed.

if ( !empty( $post->post_excerpt ) ) :

Once this action is taken into account, you can factor in what code you want to out put if the post_excerpt isn’t empty.

if ( !empty( $post->post_excerpt ) ) :
	the_excerpt();
else :
	false;
endif;

The above code checks if there is an excerpt and print’s it to the screen. If there isn’t an except, it doesn’t do anything.

Continue Reading

Tips & Tricks

Add a shortcode

Published

on

This is a simple one.

/**
 * Your Blog title
 *
 */
function my_blog_title() {
	$blogname = get_bloginfo('name');
    return '<span class="blog-title">' . $blogname . '</span>';
}		  	
add_shortcode('blog-title', 'my_blog_title');

Just add this to your functions.php file and then add [blog-title] in any post or page and it will return your Blog Title. :)

Continue Reading

Random Search Terms

Title

Recent Posts: Fully Net Worth . com

24kGoldn Net Worth: How Rich is the Upcoming Rapper Actually?

24kGoldn Net Worth: How Rich is the Upcoming Rapper Actually?

24KGoldn is a young American rapper. He is best known for his track called “Valentino” which would be a song about wanting money over love. This song was able to make it to the Billboard Hot 100 and even garnered popularity on TikTok videos. He is currently signed with the record labels LLC and Columbia. […]

Candy Ken Net Worth: How Rich is the Rapper from Austria?

Candy Ken Net Worth: How Rich is the Rapper from Austria?

Candy Ken Jakob Kasimir Hellrigl known by his stage name as Candy Ken is an Austrian rapper, model, and TikToker. Ken is best known for his masculine appearance with feminine pop culture. As of May 2020, Candy Ken’s net worth is estimated to be $2 million. Jakob was born on July 27, 1992, (Leo) in […]

Flipp Dinero Net Worth: How Rich is the Rapper Actually?

Flipp Dinero Net Worth: How Rich is the Rapper Actually?

Christopher Saint Victor, who is better known by his stage name as Flipp Dinero, is an American rapper and songwriter. He became viral after Odell Beckham, the football player posted a video of him dancing to his song called “Leave Me Alone”. As a result, the song would peak at number 20 in the Billboard […]

Tony Beets Net Worth: How Rich is the Gold Miner Actually?

Tony Beets Net Worth: How Rich is the Gold Miner Actually?

Tony Beets is a Gold Miner and one of the most popular cast members on the reality series Gold Rush which airs on Discovery. He is known to be one of the biggest gold miners in Canada and owns the Tamarack Mine and Paradise Hills. As of 2019, Tony Beets net worth is estimated to […]

Trending