Tips & Tricks
Build a classic MyBlogLog widget
In this post I will show you how I created my custom widget showcasing mybloglog readers.
In your function.php
file add this simple line of code:
<?php
// MyBlogLog
function MyBlogLogWidget()
{
?>
<script type="text/javascript" src="http://pub.mybloglog.com/comm2.php?mblID=ReplaceWithYourID
&c_width=220&c_sn_opt=n&c_rows=6&c_img_size=h&c_heading_text=&c_color_heading_bg=e0e0d4&c_color_heading=E8A02C&c_color_link_bg=e0e0d4&c_color_link=d54e21&c&c_color_bottom_bg=e0e0d4"></script>
<?php }
//register the sidebar 'the widget name', 'the widget function'//
register_sidebar_widget('MyBlogLog Widget', 'MyBlogLogWidget');
?>
That’s it, just replace the “ReplaceWithYourID
” with your mybloglog ID. You can also change the width at c_width=220
to what ever you like.
If you look closely at the code you may also see color codes, you may change them to corresponding hex codes, for example: c_color_bottom_bg=e0e0d4
is the color for the bottom background. e0e0d4
is a light gray, we can change it to ffffff
and make it white.
That’s it, enjoy!
Tips & Tricks
Remove spaces when echoing the_title
Ever wanted to print or echo the WordPress title attribute without spaces?
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; ?>&<?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.
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.
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.
Tips & Tricks
Add a shortcode
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. :)
-
Tips & Tricks4 months ago
WordPress Security Hacks
-
Pages2 months ago
Write For Us – Guest Post
-
Showcase2 months ago
StylizedWeb.com
-
News1 month ago
How to: Show/Hide any div box with jQuery in WordPress
-
Tips & Tricks3 months ago
How to: show/hide a widget in WordPress with jQuery
-
Tips & Tricks3 weeks ago
Remove the title attribute using jQuery
-
Plugins3 months ago
Top Membership plugins
-
Tips & Tricks2 months ago
Limit the characters that display on the_title
Danny
February 5, 2009 at 9:04 am
Hello, using your code, I obtain only an empty . have you got any idea?
Danny´s last blog post..Proprieta’ Font-Weight: solo un browser la supporta
frosty
February 5, 2009 at 1:23 pm
Hey Danny,
Make sure this is pasted into your
functions.php
and then you should see a ‘widget’ in your widgets area..Glenn
March 19, 2009 at 4:57 pm
Austin,
This disadvantage of placing widgets in the functions.php file is (I think) they get clobbered on an update of WordPress.
Again you could use Widgetifyr.com to easily create a stand alone widget.
Thanks
Glenn
Austin
March 19, 2009 at 7:49 pm
Thanks Glenn,
I will give your service a try with this widget.