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
Can′t add pagination on WooThemes Thick Theme
Everything I have tried has led to nothing. And I have tried six way’s from Sunday to get my main posts to paginate.
example one:
<?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('offset=1&showposts=' . get_option('woo_other_entries') . '&cat=-' . $GLOBALS['ex_asides'] . '&paged=$paged' ); ?>
example two:
<?php global $myOffset; global $wp_query; $myOffset = 1; $paged = intval(get_query_var('paged')) ? get_query_var('paged') : 1; $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query(array( 'offset' => $myOffset, 'category__not_in' => array($GLOBALS['ex_asides'],7,84), 'paged' => $paged, 'showposts' => get_option('woo_other_entries'), )); ?>
example three:
<?php global $myOffset; $myOffset = 1; $wp_query = new WP_Query(); $wp_query->query(array( 'offset' => $myOffset, 'category__not_in' => array($GLOBALS['ex_asides'],7,84), 'paged' => $paged, 'showposts' => get_option('woo_other_entries'), )); ?>
And after those tries, I just can’t get more pages beyond the option’s that I choose, and can only pull an archive via the browse more link.
Any suggestions or anything?
Tips & Tricks
Pulling custom fields from outside the loop
In the last post “Creating a custom widget” I showed you how to create a custom widget. Well in this post I will show you how I used my custom widget to display all post with a certain custom field from outside the WordPress loop.
In the last post I used this tag:
<?php include(TEMPLATEPATH . '/includes/showcase.php'); ?>
Now I will show you what the file showcase.php
has:
<ul> <?php global $wpdb; $sql = "SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'gallery-url' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY wposts.post_date DESC LIMIT 8"; $pageposts = $wpdb->get_results($sql, OBJECT); $output = $pre_HTML; foreach ($pageposts as $post) : setup_postdata($post); ?> <li><a href="<?php echo get_post_meta($post->ID, "gallery-url", $single = true); ?>" title="Link to <?php the_title(); ?>"> <img src="<?php echo get_post_meta($post->ID, "image", $single = true); ?>" alt="<?php the_title(); ?>" /></a></li> <?php endforeach; ?> </ul>
That’s it! The most important item you may want to change for your own custom field is the line : AND wpostmeta.meta_key = 'gallery-url'
. Where you would change the text in bold to match your own custom field value.
Update:
Check out Austin from PressedWords comment below.
With his great advise I was able to figure out why all my attempts to use the query_post weren’t working. it came down to this line of code: <?php echo get_post_meta($post->ID, "gallery-url", $single = true); ?>
, that was what I had in my code, and the $post->ID
is the reason my code would not echo or print the custom field’s value. Solution? replace $post->ID
with get_the_ID()
. HA, so simple.
Tips & Tricks
Creating a custom widget
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!
-
Tips & Tricks2 months ago
WordPress Security Hacks
-
Pages5 months ago
Write For Us – Guest Post
-
Showcase2 hours ago
StylizedWeb.com
-
News5 months ago
How to: Show/Hide any div box with jQuery in WordPress
-
Tips & Tricks4 months ago
Remove the title attribute using jQuery
-
Tips & Tricks1 month ago
How to: show/hide a widget in WordPress with jQuery
-
Plugins1 month ago
Top Membership plugins
-
Tips & Tricks5 months ago
Limit the characters that display on the_title