To display a specific post by post ID, add the following code to your WordPress template file. <?php //Select specific post ID $post_id=256; //To display post title echo ‘<h1>’ . get_post($post_id)->post_title . ‘</h1>’; //To display post content echo get_post($post_id)->post_content; ?> Tested with WordPress 3.3
Tag: tutorials
How to list a specific number of posts from 1 category in WordPress
You can place the following code in one of your theme’s template files to list a particular amount of posts from one of your site’s catagories. <h2>Last 5 Tutorials</h2> <?php query_posts(‘category_name=tutorials&showposts=5’); ?> <?php while (have_posts()) : the_post(); ?> <h2><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h2> <?php the_excerpt(); ?> <?php endwhile; ?> Tested with WordPress 3.3
Wrapping pre tag text in a div using css
When using pre tags in html to display code blocks it will ignore the div boundaries and not wrap the text by default. By adding some css for pre tags this can be accomplished as follows. Hint: Another option is to use overflow:auto which will add scroll bars for the content. pre, code{ /*Wrap pre […]
Add a Read More link to the_excerpt() in WordPress
To remove the default […] marker at the end of an excerpt and add a Read More link add the following code to your theme’s functions.php file function new_excerpt_more($more) { global $post; return '<a href="'. get_permalink($post->ID) . '"> Read More…</a>'; } add_filter('excerpt_more', 'new_excerpt_more'); Tested with WordPress version 3.3
Change the_excerpt() word length in WordPress
By default the WordPress the_excerpt() tag displays the first 55 words. To assign a custom length just add the following code to your theme’s functions.php file. The return value in the custom_length function will change the word length of the_excerpt() tag. function custom_length( $length ) { return 30; } add_filter( 'excerpt_length', 'custom_length', 999 ); Tested […]
Redirect WordPress login logo link
If you want your wordpress login logo to redirect to your site root add the following code to your theme’s functions.php file add_filter('login_headerurl', 'my_login_url_local'); function my_login_url_local() { return get_bloginfo('url'); } Tested with WordPress 3.3
Change WordPress login logo
If you want to change the default wordpress logo on the login page, you can add the following code to your themes functions.php file. Make sure /images/login-logo.png is present in your theme folder. function custom_login_logo() { echo '<style type="text/css">h1 a { background-image:url('.get_bloginfo('template_url').'/images/login-logo.png) !important; }</style>'; } add_action('login_head', 'custom_login_logo'); tested with wordpress version 3.3