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.
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 & Tricks
Adding a external file after the first post
How might you display a Google ad after the first post or anything you like? It is very simple. You just need to add the variable $loopcounter
in the Loop. If the $loopcounter
is less than or equal to 1, then include your option. Check out the code:
<?php if (have_posts()) : while (have_posts()) : the_post(); $loopcounter++; ?> // your loop <?php if ($loopcounter <= 1) { include (STYLESHEETPATH . '/you-file.php'); } ?> <?php endwhile; ?> <?php else : ?> <?php endif; ?>
Pretty simple huh. Well in the $loopcounter
line, you may change the include to point to any file or maybe a custom widget like so:
<?php if ($loopcounter <= 1) { dynamic_sidebar( 'Plus Post' ); } ?>
Or use your code directly in between the {
& }
.
Tips & Tricks
A simple way to query posts
Here is a simple way to call query_posts
with an array of options. For all options you my use visit: WordPress Codex.
<?php $my_query = array('showposts' => 4, 'post__not_in' => $do_not_duplicate); ?> <?php query_posts($my_query); ?>
-
Tips & Tricks4 months ago
WordPress Security Hacks
-
Pages1 month 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 & Tricks2 weeks ago
Remove the title attribute using jQuery
-
Tips & Tricks3 months ago
How to: show/hide a widget in WordPress with 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