WordPress.org

Ready to get started?Download WordPress

Forums

Changing information in categories (5 posts)

  1. cimson
    Member
    Posted 5 years ago #

    Hi!

    Have found a template that I like, but there is one problem. In each category section the complete articles are posted. When having 10 - 20 long articles on the same page it gets a bit hard do navigate…

    In each category I would like to show only the titel, the 100 first words of that article and date of publishing for every article”. Is there any solution to make this happen?

    http://www.modellrallaren.se

    /Jocke

  2. yoshi
    Member
    Posted 5 years ago #

    Use the_excerpt instead of the_content.

    However, length of the excerpt is hard coded to 55 words and you need to change that in some way - for example, putting these code in functions.php in your theme directory.

    /*
     * copied from wp_trim_excerpt in wp-includes/formatting.php
     */
    function wp_trim_excerpt_100($text) {
      if ( '' == $text ) {
        $text = get_the_content('');
        $text = strip_shortcodes( $text );
        $text = apply_filters('the_content', $text);
        $text = str_replace(']]>', ']]>', $text);
        $text = strip_tags($text);
        $excerpt_length = 100; //// Changed to 100 words ////
        $words = explode(' ', $text, $excerpt_length + 1);
        if (count($words) > $excerpt_length) {
          array_pop($words);
          array_push($words, '[...]');
          $text = implode(' ', $words);
        }
      }
      return $text;
    }
    
    remove_filter('get_the_excerpt', 'wp_trim_excerpt');
    add_filter('get_the_excerpt', 'wp_trim_excerpt_100');
  3. ronchicago
    Member
    Posted 5 years ago #

    the answer may be in the "excerpt" argument. do a search for excerpt on this forum, there are many discussions.

  4. cimson
    Member
    Posted 5 years ago #

    In the codex I found a recommendation to change the code "the_content" to "the_excerpt", but cannot find that piece of code in the categorytemplate code. Any suggestions of what part I should change?

    <div id="content">
    
    <?php if (have_posts()) : ?>
    		<div class="post">
    		<h1><?php single_cat_title(); ?></h1>
    		<?php while (have_posts()) : the_post(); $loopcounter++; ?>
    			<?php if ($loopcounter == 1) { ?> <div class="content3-left content3-separator hseparator"> <?php } ?>
    			<?php if ($loopcounter == 2) { ?> <div class="content3-left hseparator"> <?php } ?>
    			<?php if ($loopcounter == 3) { ?> <div class="content3-right hseparator"> <?php } ?>
    
    			<?php global $post; ?>
    			<?php $image = get_post_meta($post->ID, 'Image URL', true); ?>
    			<?php if(!$image) $image= get_bloginfo('stylesheet_directory').'/images/thumbnail.jpg'; ?>
    			<?php if($image) $thumbnail= get_bloginfo('stylesheet_directory').'/thumb.php?src='.$image.'&amp;w=153&amp;h=110&amp;zc=1&amp;q=80'; ?>
    			<a>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" >
    			<img src="<?php echo $thumbnail; ?>" alt="<?php the_title(); ?>" />
    			</a>
    			<h2 class="magz-gallery-title"><a>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" class="title"><?php the_title(); ?></a></h2>
    			</div>
    
    			<?php if ($loopcounter == 3) { $loopcounter =0; ?> <div class="clear" ></div> <?php } ?>
    		<?php endwhile; ?>
    		</div>
    
    		<div class="navigation">
    		<?php if(function_exists('wp_pagenavi')) : wp_pagenavi(); else : ?>
    		<div class="alignleft"><?php next_posts_link('&laquo; Older Entries') ?></div>
    		<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;') ?></div>
    		<hr class="clear"/>
    		<?php endif; ?>
    		</div>
    
    	<?php else : ?>
    
    		<div class="post">
    			<h2 class="headtitle center">Not Found</h2>
    			<p class="center">Sorry, but you are looking for something that isn't here.</p>
    			<center><?php include (TEMPLATEPATH . "/searchform.php"); ?></center>
    		</div>
    
    	<?php endif; ?>
    
      </div><!--/content -->
  5. yoshi
    Member
    Posted 5 years ago #

    Just add <?php the_excerpt(); ?> anywhere within the while loop, where you want to display the content.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.