December 8, 2011 admin
Wordpress
A handy little loop to show a short summary and replace
// find out your post permalink
$perma_link = get_permalink( $post->ID );
// save original post content to variable
$content = get_the_content();
// prevent tags strip | it's a bug in WordPress!
$content = apply_filters( 'the_content', $content );
$content = str_replace( ']]>', ']]>', $content );
// throw out trimmed: content to process, read more tag, post permalink, words length
echo trim_the_content( $content, ' ', $perma_link, 8 );
?>
December 2, 2011 admin
Wordpress
By default WordPress places the posts that are sticky before any other posts. But what if you want to run a query to show only the sticky’s? perhaps alongside another loop or on a custom page template?
That’s where this nice little loop can help, It outputs the last 15 sticky’s into a 250px box using H5 text.
<!-- start sticky -->
<div style="float:left;width:250px;">
<h4 class="widgettitle">The Sticky Posts</h4>
<?php
$sticky = get_option( 'sticky_posts' ); // Get all sticky posts
rsort( $sticky ); // Sort the stickies, latest first
$sticky = array_slice( $sticky, 0, 15 ); // Number of stickies to show
query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 15 ) ); // The query
if (have_posts() ) { while ( have_posts() ) : the_post(); ?>
<h5 class="smalllist"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h5>
<?php endwhile;?>
<?php } else { echo ""; }?>
</div>
<!-- end sticky -->