Wordpress query to pull a snippet from a post/page


/ Published in: PHP
Save to your folder(s)

This simply pulls 165 characters from a page/post. Important to reset the query.


Copy this code and paste it in your HTML
  1. <?php query_posts('pagename=about'); ?>
  2. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  3. <div><h4>Type your title here</h4>
  4. <p><?php echo substr(strip_tags($post->post_content), 0, 165); ?>... <a href="<?php bloginfo('url'); ?>/about">Read More</a></p></div>
  5. <?php endwhile; endif;
  6. //Reset Query
  7. wp_reset_query();
  8. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.