• Ive got a problem, and I have read about in another topic but didnt really got that to work.

    Im having a page where the index is a newspage. And when the news is posted I only want 300 character at the index to be displayed. And when you click at the title or the “read more” button the the news will be official.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Is this just one post on your index you want to be cut to 300 characters or all posts?

    I’m assuming it’s all posts, you’d go into your index template (most likley index.php), and change the_content to the excerpt

    Then in your functions.php file add the following:

    function new_excerpt_length($length) {
    	return 300;
    }
    function excerpt_ellipse($text) {
       return str_replace('[...]', ' <a href="'.get_permalink().'">Read More</a>', $text);
    }
    add_filter('the_excerpt', 'excerpt_ellipse');
    add_filter('excerpt_length', 'new_excerpt_length');

    The first function changes the amount shown to 300 characters and the second function changes […] to a read more link

    Thread Starter bortas

    (@bortas)

    I Have paste the function into the funtcions.php

    My code at the index looks like this.

    <?php if (have_posts()) : ?>
    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $args= array(
    	'cat' => 4,
    	'paged' => $paged
    );
    query_posts($args);
    ?>
    <?php while (have_posts()) : the_post(); ?>

    Where should i add eh exceprt?

    it goes in index.php

    are you altering a theme, or creating one?

    if altering a theme, in index.php you may just replace the call to the_content with the_excerpt

    edit…sorry, I misread, and thought the above code was from functions.php, so my reply makes little to no sense….

    Thread Starter bortas

    (@bortas)

    Its my design yes… So the index doesnt really look like anotther index.php

    Somewhere underneath the line you posted in index.php:

    <?php while (have_posts()) : the_post(); ?>

    You should find the_content(); somewhere, change it to the_excerpt.

    If you are still struggling post up your index.php file!

    Thread Starter bortas

    (@bortas)

    I solved it, thanks alot! (Y)

    No problemo

    axelav

    (@axelav)

    Hi xdesi,

    I followed your instructions but it doesn’t seem to have changed anything. Here’s my functions.php file:

    <?php
    
    function new_excerpt_length($length) {
    	return 125;
    }
    function excerpt_ellipse($text) {
       return str_replace('[...]', ' <a href="'.get_permalink().'">[More...]</a>', $text);
    }
    add_filter('the_excerpt', 'excerpt_ellipse');
    add_filter('excerpt_length', 'new_excerpt_length');
    
    ?>

    And this is what I have in my index.php file:

    <?php while (have_posts()) : the_post(); ?>
    
    				<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    					<h4><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h4>
    					<small><?php the_time('F jS, Y g:ia') ?></small>
    					<div class="news-entry">
    						<?php the_excerpt(); ?>
    					</div>
    				</div>
    
    			<?php endwhile; ?>

    Thanks!

    axelav

    (@axelav)

    Oye I sorted it out. The number the first function returns is words, not characters.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘300 Character limit’ is closed to new replies.