Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

here's the code for my archive page..

<?php
/*
Template Name: Archive Page
*/
?>

<?php get_header(); ?>
<div id ="maincontent"class = "group">
        <?php include'leftsidebar.php';?>
    <div id = "allcontent"class="archive">
    <?php if (have_posts()) : ?>

        <?php $post = $posts[0]; // Hack. Set $post so that the_date() works. ?>

        <?php /* If this is a category archive */ if (is_category()) { ?>
            <h2>Archive for the &#8216;<?php single_cat_title(); ?>&#8217; Category</h2>

        <?php /* If this is a tag archive */ } elseif( is_tag() ) { ?>
            <h2>Posts Tagged &#8216;<?php single_tag_title(); ?>&#8217;</h2>

        <?php /* If this is a daily archive */ } elseif (is_day()) { ?>
            <h2>Archive for <?php the_time('F jS, Y'); ?></h2>

        <?php /* If this is a monthly archive */ } elseif (is_month()) { ?>
            <h2>Archive for <?php the_time('F, Y'); ?></h2>

        <?php /* If this is a yearly archive */ } elseif (is_year()) { ?>
            <h2>Archive for <?php the_time('Y'); ?></h2>

        <?php /* If this is an author archive */ } elseif (is_author()) { ?>
            <h2>Author Archive</h2>

        <?php /* If this is a paged archive */ } elseif (isset($_GET['paged']) && !empty($_GET['paged'])) { ?>
            <h2>Blog Archives</h2>

        <?php } ?>

        <?php include (TEMPLATEPATH . '/inc/nav.php' );?>

        <ul>
        <?php $i=0;?>

        <?php while (have_posts()) : the_post(); ?>
            <?php $i++; ?>
            <li class ="group">
            <div <?php post_class() ?>>

                <h2 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>

                <?php include (TEMPLATEPATH . '/inc/meta.php' ); ?>

                <div class="entry">

                    <?php the_content();?>
                </div>

            </div>
            </li>
            <?php 
            $Archive_Ads = array(
            'Archive Ad1',
            'Archive Ad2',
            'Archive Ad3'
            );
            if ($i % 3 === 0):
            if (function_exists('dynamic_sidebar')) :/*this is the line 69*/
            dynamic_sidebar($Archive_Ads[rand(0, 2)]);
            endif;
            endif;
            ?>

        <?php endwhile; ?>
        </ul>



        <?php include (TEMPLATEPATH . '/inc/nav.php' ); ?>

<?php else : ?>

    <h2>Nothing found</h2>

<?php endif; ?>


    </div>
</div>
<?php get_footer(); ?>

Now What I want is to limit the text by 50 words without affecting the videos and images, I want my Images and Videos to be display, is it possible to do that?

share|improve this question
    
So when you're on the Archive page, you just want to display the first 50 words? –  Rutwick Gangurde Nov 24 '11 at 4:04
    
yup, that's what I wanted., I forgot to say.. the images and videos are just inserted in the post, I'm not using the featured Image. –  markyeoj Nov 24 '11 at 4:14

1 Answer 1

up vote 0 down vote accepted

I'm assuming 'Archive Page' is a custom template and not either of the WP archive pages (category/date/author/tag/taxonomy). Try using this:

<?php
add_filter('the_content', 'trim_content');

function trim_content($content)
{
    if(is_archive())
    {
        //use your own trick to get the first 50 words. I'm getting the first 100 characters just to show an example.
        $content = (strlen($content) <= 100)? $content : wp_html_excerpt($content, 100);
    }

    return $content;
}

I think this will do the job.

share|improve this answer
    
It's now working for me, I added the funtion in my functions.php and relplace my <?php the_content();?> with <?php trim_content($content);?> in my archive. is there somthing wrong from what I've did? sorry, I'm not good in PHP.. –  markyeoj Nov 24 '11 at 5:29
    
You just need to add this in functions.php, WP will take care of the function call! Leave the_content() as it is. Also, have you put the filename with the extension properly? –  Rutwick Gangurde Nov 24 '11 at 5:33
    
add_filter('the_content', 'trim_content'); function trim_content($content) { if(is_page_template('archive.php')) { //use your own trick to get the first 50 words. I'm getting the first 100 characters just to show an example. $content = (strlen($content) <= 50)? $content : wp_html_excerpt($content, 50); } return $content; } tha'ts the code that I added to my functions.php, and nothings happen. –  markyeoj Nov 24 '11 at 5:54
    
Ohh! It means you're using WPs archives. I'm changing my code in the answer. Please check. –  Rutwick Gangurde Nov 24 '11 at 5:57
    
How can I give you a reputation?, sorry I didn't know. –  markyeoj Nov 24 '11 at 6:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.