Tips & Tricks
Limit the characters that display on the_title
Ever wanted to display the title of a post somewhere but limit the amount of characters that are shown? For instance, this post has a very long title, and if I were to use <?php echo the_title() ?>
it would show as follows: Limit the characters that display on the_title.
That may not fit well on one line in lets say a widget or small width div
. So here is a neat trick you can use:
<?php $title = the_title('','',FALSE); echo substr($title, 0, 11); ?>
Pretty simple huh, just note the bold numbers, in this case 11 character would output like this: Limit the c.
Thanks to Tattershall Way for this snippet.
Themes
Add additional meta boxes to Hybrid Theme
At the time of writing this post I have Theme Hybrid as my parent theme, and am using a custom version of Hybrid News that Justin Tadlock offers to the public.
Well I want to tell you how you can add additional custom meta boxes to your child theme’s running the Hybrid Theme.
In your child function.php
file just add the following to create a new post meta box:
/** * Add additional post meta boxes * * by WPCult */ function wpcult_post_meta_boxes($meta_boxes) { $meta_boxes['image'] = array( 'name' => 'image', 'default' => '', 'title' => __('Image:'), 'type' => 'text', 'show_description' => false, 'description' => __('Please use a full size image, larger than 500px (this photo will dynamically re-size itself!'), ); return $meta_boxes; } add_filter('hybrid_post_meta_boxes', 'wpcult_post_meta_boxes');
This will create a custom meta box called Image, and will create a custom field with the id of image.
Additionally you can create this on pages as well by copy/paste and replacing “post_meta_box” with “page_meta_box” every where inside the function.
Tips & Tricks
Sick of images being to large for the content area?
Have you ever uploaded an image that might have been a tad bigger than the width of your content area? I know I have! So here is a little CSS fix to handle these situations.
.post img { max-width: 600px; height: auto; }
That’s it, really simple huh. Just make sure that you change the .post
to the correct body class(which starts with a “.“) or body ID(which starts with a “#“).
Would you like a quick explanation?
The CSS is just telling any image inside the class of .post
to not be more than 600px wide. By the way make sure you change it to fit the dimension of your content width. And the height attribute is set to auto to automatically change the height to match the new width. 🙂
Tips & Tricks
How to: Display RSS feeds from anywhere
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.
-
Tips & Tricks4 months ago
WordPress Security Hacks
-
Pages1 month ago
Write For Us – Guest Post
-
Showcase2 months ago
StylizedWeb.com
-
News4 weeks 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 & Tricks6 days ago
Remove the title attribute using jQuery
-
Plugins3 months ago
Top Membership plugins
-
Tips & Tricks5 months ago
Remove spaces when echoing the_title
Pingback: WordPress links week 4 - 2009 | WPStart.org - WordPress themes, plugins and news
Daniel
May 23, 2009 at 7:04 am
Cheers. Very useful. 🙂
I don’t suppose could help me with adding a little extra to this. I want to put “…” at the end if the amount of chars in the title exceeds the cut off point.
Austin
May 25, 2009 at 2:45 pm
Hmm, not really sure how to print that if, and only if characters are less than whats printed. May want to chack out pnp.net