Spangles Posted August 31, 2008 Share Posted August 31, 2008 Hi all I am extremely new to PHP and trying to modify a WordPress theme called Monochrome. By default, it displays the full post text on the home page and I want to be able to truncate this to say, 100 characters. Can anyone help? I think this is the code snippet that needs to be modified. <!-- BOTTOM LEFT FOUR CATEGORY LISTINGS --> <?php // enter the IDs of the categories to display $display_categories = array('3','19','20','21'); foreach ($display_categories as $category) { ?> <div class="column span-4 append-1"> <div class="five_posts"> <?php query_posts("showposts=1&cat=$category"); $wp_query->is_category = false; $wp_query->is_archive = false; $wp_query->is_home = true; ?> Thanks in advance Link to comment https://forums.phpfreaks.com/topic/122086-truncating-number-of-post-characters-to-display-on-home-page/ Share on other sites More sharing options...
JasonLewis Posted August 31, 2008 Share Posted August 31, 2008 I don't see any variable that would have anything to do with the actual post. Basically what you need to do is substr() the string. Example: $string = "This is a really long string that we want to be shortened!"; $string = substr($string, 0, 25) . "..."; //This shortens it by 50 characters and places ... at the end echo $string; Link to comment https://forums.phpfreaks.com/topic/122086-truncating-number-of-post-characters-to-display-on-home-page/#findComment-630304 Share on other sites More sharing options...
Spangles Posted August 31, 2008 Author Share Posted August 31, 2008 This is the full code behind the Main Index Template (index.php) page. I don't see a reference to the string anywhere. Do I need to be looking somewhere else? <?php get_header(); ?> <!--BEGIN SLIDESHOW POSTS--> <div id="feature" class="column span-15 first"> <script type="text/javascript"> function startGallery() { var myGallery = new gallery($('myGallery'), { timed: true, showArrows: false, showInfopane: true, showCarousel: false }); } window.addEvent('domready', startGallery); </script> <div id="myGallery"> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="imageElement"> <a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>" class="open"></a> <img src="<?php $key="photo"; echo get_post_meta($post->ID, $key, true); ?>" class="full" alt="<?php the_title(); ?>" /><img src="<?php $key="small_photo"; echo get_post_meta($post->ID, $key, true); ?>" class="thumbnail" alt="<?php the_title(); ?>" /> <h3><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" class="title"><?php the_title(); ?></a></h3> <?php the_excerpt(); ?> </div> <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?> </div> <hr class="space" /> </div> <!--END SLIDESHOW POSTS--> <!--BEGIN RIGHT SIDE--> <div class="column span-7 prepend-1 last topright news"> <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar-Single') ) : ?> <?php endif; ?> </div> <hr class="space" /> <!--END RIGHT SIDE--> <!-- BOTTOM LEFT FOUR CATEGORY LISTINGS --> <?php // enter the IDs of the categories to display $display_categories = array('3','19','20','21'); foreach ($display_categories as $category) { ?> <div class="column span-4 append-1"> <div class="five_posts"> <?php query_posts("showposts=1&cat=$category"); $wp_query->is_category = false; $wp_query->is_archive = false; $wp_query->is_home = true; ?> <h6 class="category_head"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></h6> <?php while (have_posts()) : the_post(); ?> <?php $values = get_post_custom_values("thumbnail"); if (isset($values[0])) { ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img class="photo_align_left" src="<?php $key="thumbnail"; echo get_post_meta($post->ID, $key, true); ?>" alt="<?php the_title(); ?>" /></a> <?php } ?> <h6><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" class="title"><?php the_title(); ?></a></h6> <div class="excerpt_small"> <?php the_excerpt(); ?> </div> <?php endwhile; ?> </div> </div> <?php } ?> <!-- LAST CATEGORY LISTING - NEEDED TO END CSS COLUMNS --> <?php // enter the IDs of the categories to display $display_categories = array('22'); foreach ($display_categories as $category) { ?> <div class="column span-4 last"> <div class="five_posts"> <?php query_posts("showposts=1&cat=$category"); $wp_query->is_category = false; $wp_query->is_archive = false; $wp_query->is_home = true; ?> <h6 class="category_head"><a href="<?php echo get_category_link($category);?>"><?php single_cat_title(); ?></a></h6> <?php while (have_posts()) : the_post(); ?> <?php $values = get_post_custom_values("thumbnail"); if (isset($values[0])) { ?> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><img class="photo_align_left" src="<?php $key="thumbnail"; echo get_post_meta($post->ID, $key, true); ?>" alt="<?php the_title(); ?>" /></a> <?php } ?> <h6><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" class="title"><?php the_title(); ?></a></h6> <div class="excerpt_small"> <?php the_excerpt(); ?> </div> <?php endwhile; ?> </div> </div> <?php } ?> <hr /> <?php get_sidebar(); ?> <?php get_footer(); ?> Link to comment https://forums.phpfreaks.com/topic/122086-truncating-number-of-post-characters-to-display-on-home-page/#findComment-630305 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.