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

How to: Display RSS feeds from anywhere

Published

on

Here is a simple way to display any RSS feed in your WordPress blog.

<?php include_once(ABSPATH . WPINC . '/rss.php');
	$rss = fetch_rss('http://feeds2.feedburner.com/WPCult');
	$items = array_slice($rss->items, 0, 4);

		if (empty($items)) echo '<li>No items</li>';
		else
			foreach ( $items as $item ) : ?>
            <a style="font-size: 14px;" href='<?php echo $item['link']; ?>' title='<?php echo $item['title']; ?>'><?php echo $item['title']; ?></a><br /> 
            <p style="font-size: 10px; color: #aaa;"><?php echo date('F, j Y',strtotime($item['pubdate'])); ?></p>
            <p><?php echo substr($item['summary'],0,strpos($item['summary'], "This is a post from")); ?></p>
            <?php endforeach; ?>

The first step is to include the WordPress file rss.php then will apply code after to style the feeds.

Of coarse I forgot to mention, change the RSS feed to the feed you want to pull.

Continue Reading

Tips & Tricks

Remove the title attribute using jQuery

Published

on

In WordPress, when you use wp_page_menu your anchor attribute’s usually carry a title with the same name. I’m not sure if it’s correct to do this, but it bother me when I hover over a page menu navigation link and I get a hover of the title.

So on my site I used jQuery to remove the title:

$("#nav a").removeAttr("title");

Pretty simple huh?

Continue Reading

Tips & Tricks

How to: Open external links in a new window

Published

on

Over the weekend, I attended WordCamp Denver, and I was asked by John Hawkins how to force links to open in a new tab with out editing the source code. So, today lets learn a simple jQuery trick to open all external links in your site in a new tab or window. We are going to make sure you have jQuery active on your site, you can do this easily in WordPress, since it’s bundled with the latest installations. Use this code in your header: <?php wp_enqueue_script('jquery'); ?> then, below the wp_head add the following:

<script type="text/javacript">
var $j = jQuery.noConflict();

$j(document).ready(function() {
//external attribute
    $j("a:not([@href*=http://YOURSITE.com/])").not("[href^=#]")
        .addClass("external")
        .attr({ target: "_blank" });
    }
);
</script>

That’s it, just make sure you change the http://YOURSITE.com to your website.

Update

If you like you can remove the var $j = and replace all $j with simply just $

 

Continue Reading

Random Search Terms

Title

Recent Posts: Fully Net Worth . com

Omi In A Hellcat Net Worth: How Much is the YouTuber Worth?

Omi In A Hellcat Net Worth: How Much is the YouTuber Worth?

Omi In a Hellcat is an American YouTube personality and entrepreneur who depicts his sensational lifestyle through vlogs on his YouTube channel. As of 2019, Omi In A Hellcat net worth is estimated to be $60 million. Unfortunately, Omi’s real name is unavailable to us. He was born on August 6, 1985, in Philadelphia, United […]

Deontay Wilder Net Worth 2020

Deontay Wilder Net Worth 2020

Deontay Wilder Net Worth 2020 Deontay Wilder is an American professional boxer. He initially wanted to play basketball before turning to boxing as a career. Deontay Wilder is currently a WBC heavyweight champion of the world. He is one of the best professional boxers in the world at the moment. He was also considering American […]

Roddy Ricch Net Worth: 5 Interesting Facts You Should Know

Roddy Ricch Net Worth: 5 Interesting Facts You Should Know

Rodrick Wayne Moore, Jr., who is better known by his stage name as Roddy Ricch, is an American rapper, singer, songwriter and record producer. Here are some interesting facts about Roddy Ricch including his personal fortune, earnings, career and more. 1. He started rapping at the age of 8 Rodrick was born on October 24, […]

Joey Chestnut Net Worth: How Rich is the Competitive Eater Actually?

Joey Chestnut Net Worth: How Rich is the Competitive Eater Actually?

Joseph Christian Chestnut is an American competitive eater. But, he isn’t just any competitive eater, he is currently ranked as number one in this unique sport according to Major League Eating. As of 2019, Joey Chestnut net worth is estimated to be $2 million. Chestnut was born on November 25, 1983, in Vallejo, California. Having grown […]

Trending