wordpress post excerpts issue

I am using excerpts in a blog template on the home page to show 2 page excerpts with read more buttons and 1 latest blog post with a read more button.

Below is the code used

Read More
<?php
/*******PAGES SECTION CUSTOM*******/
  $args=array(
  'orderby' =>'parent',
  'order' =>'asc',
  'post_type' =>'page',
  'post__in' => array(34,36),

   );
   $page_query = new WP_Query($args); ?>
<div class="pagesarea left">
<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
   <div class="section">
    <h2 class="homeh2"><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
<?php the_excerpt(); ?>
        <p class="readmore"><a href="<?php the_permalink();?>">Read More</a></p>
</div>
 <?php endwhile; ?>




 <?php 
                                /*******LATEST NEWS SECTION*******/

            $news_text = get_theme_option(tk_theme_name.'_home_news_text');
            $news_per_page = get_theme_option(tk_theme_name.'_home_news_number');
            $blog_id =  get_option('id_blog_page');
            $blog_url = get_permalink($blog_id);

                if($hide_news == 'yes') {}else{
        ?>

                     <div class="section last">
<h2 class="homeh2"><a href="<?php the_permalink();?>"><?php _e('Latest News ', tk_theme_name) ?></a></h2>




                <?php
                $post_counter = 1;
                $paged = (get_query_var('paged')) ? get_query_var('paged') : 0;
                $args=array('post_type' => 'post', 'post_status' => 'publish', 'posts_per_page' => $news_per_page, 'ignore_sticky_posts'=> 1);

                //The Query
                query_posts($args);

                //The Loop
                if ( have_posts() ) : while ( have_posts() ) : the_post();
                $post_day =  get_the_time('d M');
                $post_year =  get_the_time('Y');
                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'home-news');
                $post_cats = get_the_category_list(',', $post->ID);
                $cat_array = explode(',', $post_cats);
                $number_of_cats = count($cat_array);
                $cat_counter = 1;
                $format = get_post_format();
                ?>


                        <p class="title"><?php echo $post_day?>
                        <?php echo $post_year?>

                        <?php the_title()?>
                        </p>

                                 <?php the_excerpt(); ?>
<p class="readmore"><a href="<?php the_permalink();?>">Read More</a></p>
                        </div>

            <?php $post_counter++;endwhile; ?>
            <?php else: ?>
            <?php endif; ?>


        <?php } // if news   ?>

The code works for the 2 pages, but for the post it does not take an excerpt it uses the full text and it overflows the p tag.

the link to the website is here: http://green.romeomothersugar.co.uk

Any help would be appreciated!

Related posts

Leave a Reply

2 comments

  1. As I inspect it , it seems that it is taking your sentence as a single word. Though I think it will get solve if you insert some real/proper data.

    A quick solution to wrap word is try giving below CSS to your p tag.

    word-wrap: break-word;

  2. It seems your problem has little to do with your code, and much to do with the actual content of the post in the database.

    Inspecting the source code, all the words ‘test’ are followed by a &nbsp;, i.e. a Non Breaking Space Character. That kind of says it all, it’s an HTML entity designed to prevent any line breaks, for instance when you’re formatting tabular data and want a first and last name on one line.

    Try going into your WordPress admin area and edit the offending post. Change from WYSIWYG to HTML editing mode, and see if it’s something along the lines of Test test test test test or Test&nbsp;test&nbsp;test&nbsp;. If it’s the latter, WordPress will interpret the entire post as one single word, so there’s no reason for WordPress not to include everything in the excerpt, which has a default 55 word limit.

    Also, the reason your text is overflowing has everything to do with the &nbsp; entities. Again, the line won’t break as it normally would, so the line of text overflows the div.section list.