• Resolved JCataln

    (@jcataln)


    Hey,

    I am currently working on making slightly more unique, and better serving to the reader. For reference, you can see my index page at: https://www.economicthought.net

    As you can see, the first article (or the latest article to be published) is quoted in its entirety on the index page, not making it obvious to the reader that he or she should click on the header and be taken to the permanent page (where all the images and whatnot are shown). Effectively, what I want to do is limit the amount of content for that first article to 300 words and then have a “…(read more)” link at the end. That way, it will force the reader to go to the actual page.

    The relevant section of code, I think, is:

    <div class="entry">
    					<?php
    $content = get_the_content('read more');
    $content = apply_filters('the_content', $content);
    $content = preg_replace('|<img (.+?)>|i', '', $content);
    $content = preg_replace('|<div id="attachment_(.+?)" class="wp-caption(.+?)<\/div>|i', '', $content);
    echo $content;      ?>
    				</div>

    All the code is:

    <?php
    get_header(); ?>
    
    <div id="content-wrap">
    	<div id="content">
    
    <?php if ( $paged < 2 ) {  // Do stuff specific to first page  ?>
    
    	<?php if (have_posts()) : ?>
          <?php
    $sticky=get_option('sticky_posts');
    $args=array(
       'caller_get_posts'=>1,
       'post__not_in' => $sticky,
       'posts_per_page'=>1,
       );
          $my_query = new WP_Query($args);
      while ($my_query->have_posts()) : $my_query->the_post();
      $do_not_duplicate = $post->ID;?>
          <div class="xxxpost lastlast" id="post-<?php the_ID(); ?>">
    <div class="lastimage">
    <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><div class="pik" style="background: url(<?php the_post_image_url('medium'); ?>) center top no-repeat; width: 250px; height:200px; border: 1px solid #777;">
    </div></a>
    </div>
    
    <div class="atas-post"><?php the_time('F jS, Y') ?> - <?php the_time() ?> <!-- &sect; <?php _e('by'); ?> <?php the_author() ?>  --> &sect; in  <?php the_category(', ') ?></div>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    <br />
    <p><i><b>Written by:</b>
    <?php the_author_posts_link(); ?></i></p>
    <br /><br />
    
    				<div class="entry">
    					<?php
    $content = get_the_content('read more');
    $content = apply_filters('the_content', $content);
    $content = preg_replace('|<img (.+?)>|i', '', $content);
    $content = preg_replace('|<div id="attachment_(.+?)" class="wp-caption(.+?)<\/div>|i', '', $content);
    echo $content;      ?>
    				</div>
    
    				<div class="postmetadata"><span class="lefter"><?php the_tags('Tags: ', ', ', ''); ?></span> <span class="righter"><?php edit_post_link('Edit', '', '  '); ?>  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></div>
    </div>
    
          <?php endwhile; ?>
    <br class="clear" />
    <?php
     $counter = 0; $counter2 = 0;
    $args=array(
       'caller_get_posts'=>1,
       'post__not_in' => $sticky,
       'paged'=>$paged,
       'posts_per_page'=>7,
       );
    query_posts($args);
    while (have_posts()) : the_post();
      if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); 
    
     $counter++; $counter2++;
      ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    			<div class="<?php if ($counter == 1) { echo 'leftside'; } else { echo 'rightside'; $counter = 0; } ?>">
    <div class="atas-post"><?php the_time('F jS, Y') ?> - <?php the_time() ?> <!-- &sect; <?php _e('by'); ?> <?php the_author() ?>  -->&sect; in  <?php the_category(', ') ?></div>
    
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <div class="theimage">
    <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><div class="pik" style="background: url(<?php the_post_image_url('thumbnail'); ?>) center center no-repeat; width: 150px; height:110px; border: 1px solid #777;">
    </div></a>
    
    </div>
    				<div class="entry">
    					<p><?php
    						$texter = get_the_excerpt();
    						if(strlen($texter ) > 300) {
    						$texter = substr($texter , 0, 300);
    						}
    						echo ''.$texter.'[...]';
    						?>
    						</p>
    				</div>
    
    <br />
    <p><i><b>Written by:</b>
    <?php the_author_posts_link(); ?></i></p>
    <br /><br />
    
    				<div class="postmetadata"><span class="lefter"><?php the_tags('Tags: ', ', ', ''); ?></span> <span class="righter"><?php edit_post_link('Edit', '', '  '); ?>  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></div>
    
    			</div>
    
    <br class="clear" />			</div>
    
    		<?php endwhile; ?>
    <br class="clear" />
    
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
          <div class="navigation">
            <div class="alignleft">
              <?php next_posts_link('&larr; Previous Entries') ?>
            </div>
            <div class="alignright">
              <?php previous_posts_link('Next Entries &rarr;') ?>
            </div>
          </div>
          <?php } ?>
    
    	<?php else : ?>
    
    		<h2 class="center">Not Found</h2>
    		<p class="center">Sorry, but you are looking for something that isn't here.</p>
    		<?php get_search_form(); ?>
    
    	<?php endif; ?>
    <?php } else { // Do stuff specific to non-first page ?>
    <?php
     $counter = 0; $counter2 = 0;
    $args=array(
       'caller_get_posts'=>1,
       'post__not_in' => $sticky,
       'paged'=>$paged,
       'posts_per_page'=>6,
       );
    query_posts($args);
     while (have_posts()) : the_post();
     $counter++; $counter2++;
    ?>
    
    			<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    <div class="<?php if ($counter == 1) { echo 'leftside'; } else { echo 'rightside'; $counter = 0; } ?>">
    <div class="atas-post"><?php the_time('F jS, Y') ?> - <?php the_time() ?> <!-- &sect; <?php _e('by'); ?> <?php the_author() ?>  -->&sect; in  <?php the_category(', ') ?></div>
    <div class="theimage">
    <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>"><div class="pik" style="background: url(<?php the_post_image_url('thumbnail'); ?>) center center no-repeat; width: 150px; height:110px; border: 1px solid #777;">
    </div></a>
    </div>
    <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    				<div class="entry">
    					<p><?php
    						$texter = get_the_excerpt();
    						if(strlen($texter ) > 300) {
    						$texter = substr($texter , 0, 300);
    						}
    						echo ''.$texter.'[...]';
    						?>
    						</p>
    				</div>
    
    				<div class="postmetadata"><span class="lefter"><?php the_tags('Tags: ', ', ', ''); ?></span> <span class="righter"><?php edit_post_link('Edit', '', '  '); ?>  <?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></span></div>
    			</div>
    			</div>
    
    		<?php endwhile; ?>
    <br class="clear" />
    
    <?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } else { ?>
          <div class="navigation">
            <div class="alignleft">
              <?php next_posts_link('&larr; Previous Entries') ?>
            </div>
            <div class="alignright">
              <?php previous_posts_link('Next Entries &rarr;') ?>
            </div>
          </div>
          <?php } ?>
    
    <?php } ?>
    	</div>
    </div>
    
    <br class="clear" />
    
    <?php get_sidebar(); ?>
    
    <?php get_footer(); ?>

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Restricting size of content on Index’ is closed to new replies.