Different Excerpt Length for Different Pages
-
Hi,
I’ve few categories in my website. I don’t want to show excerpts in the category archives so I’m using Advanced Excerpt plugin for that. My website is using a static home page. I’ve another page with name blog showing all the posts according to date. This page is showing full post in Excerpt. I want to set some length for that. How can I do so?
-
Hello
Here’s a way to do with mb_strlen in the desired loop or otherwise. It can replace the php the_content
<?php if ( mb_strlen( get_the_content() ) >= 100 ) echo mb_substr( get_the_content(), 0, 100 ).’…’; else the_content(); ?>
the number 100 is the number of character. adapts
Gives in Latest News
Thanks for reply
Please guide me where to put the script?
go in the file that displays your results posts
loop.php or template page -> postsreplace <php the_content();?>
width
<? php if (mb_strlen (get_the_content ())> = 100) echo mb_substr (get_the_content (), 0, 100) ‘…’; else the_content ()? >
I made a lot page with name “blog” and page attribute is “blog (full post)” as when I select “blog except” it show zero word except as i used advanced excerpts plugin to show zero word except. Now please tell me that which file would it be which will affect “blog”page. Sorry for requesting so much detail as newbie in php.
Have you the link of you website ?
I think it’s in your loop.php !
but I’m not in your theme.
otherwise see if you have such template-blog.php or that looks like that! otherwise copy the code in your loop.php.good luck …
give newsTony
OK thanks Tony. Let me see.
Dear friend,
This is the error message in getting after pasting the code:
Parse error: syntax error, unexpected T_IF in /home/u902547838/public_html/wp-content/themes/responsive-child-theme/blog-excerpt.php on line 60
Following is the code of blog-except.Php
<?php // Exit if accessed directly if ( !defined('ABSPATH')) exit; /** * Blog Template * Template Name: Blog Excerpt (summary) * * @file blog-excerpt.php * @package Responsive * @author Emil Uzelac * @copyright 2003 - 2012 ThemeID * @license license.txt * @version Release: 1.0 * @filesource wp-content/themes/responsive/blog-excerpt.php * @link https://codex.www.ads-software.com/Templates * @since available since Release 1.0 */ ?> <?php get_header(); ?> <div id="content-blog" class="grid col-620"> <?php if ( get_query_var('paged') ) $paged = get_query_var('paged'); elseif ( get_query_var('page') ) $paged = get_query_var('page'); else $paged = 1; query_posts("post_type=post&paged=$paged"); ?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <h1 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php printf(__('Permanent Link to %s', 'responsive'), the_title_attribute('echo=0')); ?>"><?php the_title(); ?></a></h1> <div class="post-meta"> <?php responsive_post_meta_data(); ?> <?php if ( comments_open() ) : ?> <span class="comments-link"> <span class="mdash">—</span> <?php comments_popup_link(__('No Comments ↓', 'responsive'), __('1 Comment ↓', 'responsive'), __('% Comments ↓', 'responsive')); ?> </span> <?php endif; ?> </div><!-- end of .post-meta --> <div class="post-entry"> <?php if ( has_post_thumbnail()) : ?> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" > <?php the_post_thumbnail(); ?> </a> <?php endif; ?> <?php the_excerpt(); ?> <?php wp_link_pages(array('before' => '<div class="pagination">' . __('Pages:', 'responsive'), 'after' => '</div>')); ?> </div><!-- end of .post-entry --> <div class="post-data"> <?php the_tags(__('Tagged with:', 'responsive') . ' ', ', ', '<br />'); ?> <?php printf(__('Posted in %s', 'responsive'), get_the_category_list(', ')); ?> </div><!-- end of .post-data --> <div class="post-edit"><?php edit_post_link(__('Edit', 'responsive')); ?></div> </div><!-- end of #post-<?php the_ID(); ?> --> <?php endwhile; ?> <?php if ( $wp_query->max_num_pages > 1 ) : ?> <div class="navigation"> <div class="previous"><?php next_posts_link( __( '‹ Older posts', 'responsive' ) ); ?></div> <div class="next"><?php previous_posts_link( __( 'Newer posts ›', 'responsive' ) ); ?></div> </div><!-- end of .navigation --> <?php endif; ?> <?php else : ?> <h1 class="title-404"><?php _e('404 — Fancy meeting you here!', 'responsive'); ?></h1> <p><?php _e('Don't panic, we'll get through this together. Let's explore our options here.', 'responsive'); ?></p> <h6><?php _e( 'You can return', 'responsive' ); ?> <a href="<?php echo home_url(); ?>/" title="<?php esc_attr_e( 'Home', 'responsive' ); ?>"><?php _e( '← Home', 'responsive' ); ?></a> <?php _e( 'or search for the page you were looking for', 'responsive' ); ?></h6> <?php get_search_form(); ?> <?php endif; ?> </div><!-- end of #content-blog --> <?php get_sidebar('right'); ?> <?php get_footer(); ?>
And I replaced
<?php the_excerpt(); ?>
with the code provided in above comments. Can you please guide me where is wrong?
Blog-except.php is actually the page template I’m using for my blog page. And the code
<?php the_excerpt(); ?>
picks the except of the post to show s the content of the posts on blog page. As I mentioned in the post that I used Advanced Except Plugin to stop showing excerpt (under categories archives) but I want to show excerpt of desired length on blog page using blog excerpt.php. Due to
<?php the_excerpt(); ?>
code it picks excerpt which is zero so it show only titles of the posts on the blog page. After replacing the said code with the code provided in earlier comments, it started giving error. So where is wrong. Please help.
Anyone?
My blog page is offline for about two months. Any one who could help?
- The topic ‘Different Excerpt Length for Different Pages’ is closed to new replies.