How to retrieve “sticky” post outside the “loop”?

I am using this query; <?php $sticky = get_option( ‘sticky_posts’ ); // Get all sticky posts rsort( $sticky ); // Sort the stickies, latest first $sticky = array_slice( $sticky, 0, 1 ); // Number of stickies to show query_posts( array( ‘post__in’ => $sticky, ‘caller_get_posts’ => 1 ) ); // The query if (have_posts() ) { … Read more

How to insert content from another Custom Post type into Post?

Currently the best way I know to handle that is the Posts 2 Posts plugin: http://wordpress.org/extend/plugins/posts-to-posts/ Here’s an example showing how to set up the custom post types (if you already have them it’s more for other’s benefit who might be reading this) as well as the function call to p2p_register_connection_type() needed by the plugin … Read more

Multiple loops on the same page removing post tags

Sorry guys, stupid mistake, I forgot to reset the second loop using wp_reset_query, here is the working code, <?php query_posts(array(‘category_name’ => ‘test’)); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div><?php the_excerpt(); ?></div> <?php endwhile; ?> <?php endif; ?> <?php wp_reset_query(); ?> Thanx anyways though!

Static Front-Page Excerpts

Is there any particular reason not to use the front-page.php template file, and just not bother with trying to pull WordPress headers into external files? Using the front-page.php template file is easy: Create a new static Page, with any arbitrary name (let’s call it “Front Page”) Go to Dashboard -> Settings -> Reading and set … Read more

Differentiate between posts and pages in search results

Try this… <?php //prevent this div from displaying for pages: if ( get_post_type() != ‘page’ ) : ?> <div class=”searchdate”><?php the_time(‘F jS, Y’) ?></div> <?php endif; ?> The is_page() conditional tag only checks if currently displayed content is a single page view. Nothing for you at this point. See http://codex.wordpress.org/Function_Reference/is_page

Custom excerpt function re-factoring

I’d simply set a flag as second input argument for the function: function new_wp_trim_excerpt( $text, $case=”plain” ) { switch ( $case ) { default : case ‘plain’ : // do stuff – your function so far break; case ‘image’ : break; } } Notes: Avoid names like class=”moarplz”. It’s hard to read for others and … Read more