• Resolved randis83

    (@randis83)


    The use case is that I want to list the most recent posts on a page. Each post containing only the summary and title and a link to the full post.

    I have created a template called Latest Posts and it loads ok. However I want get_content() to somehow understand that this template is an archive template and therefore only display the excerpt and not the full post.

    I use the following “content” template for all other listings and would like to reuse it when listing my latest posts, but since it isn’t either a search or an archive the first selection is skipped, and the_content() will show the whole post.

    <?php if ( is_search() ) : // Only display Excerpts for Search ?>
    <div class="entry-summary">
        <?php the_excerpt(); ?>
    </div><!-- .entry-summary -->
    <?php else : ?>
    <div class="entry-content">
        <?php the_content( __( 'Continue reading <span class="meta-nav">&rarr;</span>', 'bbl' ) ); ?>
        <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'bbl' ), 'after' => '</div>' ) ); ?>
    </div><!-- .entry-content -->
    <?php endif; ?>

    Any ideas? I’ve been looking around for ideas, and I’ve seen a lot of different ways to make archives, but I haven’t been able to put it all together to fit my use case.

Viewing 4 replies - 1 through 4 (of 4 total)
  • WordPress has many if_XXX functions.

    I hope is_archive will help you.
    http://codex.wordpress.org/Function_Reference/is_archive
    Or, you can use is_single.
    http://codex.wordpress.org/Function_Reference/is_single

    Thread Starter randis83

    (@randis83)

    Thank you for your answer Fumito, but unfortunately this will not help. if_archive will only tell me if it is an archive or not. It does not give me the option to tell wordpress it is an archive. It appears, by looking at the source code, that it only evaluates to an archive if you borwse by Tags, category, author and possible some other criteria that I forgot, but there seems to be no way to tell wordpress explicit that the page I created should be treated as an archive.

    Kind of odd that I can’t find such a feature. Analyzing the code it does look like you could intercept the query object and assign the is_archive property a true value, but I would rather not do that since it might result in very unpredicted side effects.

    What you are going to do is, displaying excerpts on some page(s) , right?

    is_page will be a help.
    http://codex.wordpress.org/Function_Reference/is_page

    is_page();
    // When any single Page is being displayed.

    is_page(42);
    // When Page 42 (ID) is being displayed.

    is_page(‘Contact’);
    // When the Page with a post_title of “Contact” is being displayed.

    <?php if ( is_page() ) :  ?>
        <?php the_excerpt(); ?>
    <?php endif; ?>

    If is_page is not enough, please see http://codex.wordpress.org/Conditional_Tags
    You can create your own criteria by using these is_XXX.

    <?php if ( is_page() || is_archive() ) :   // either page, or archive will show the_excerpt  ?>
        <?php the_excerpt(); ?>
    <?php endif; ?>
    Thread Starter randis83

    (@randis83)

    I guess that is the way to go. It feels a bit weird to make a conditional test for something else rather than what i want to know. In this special scenario it does play out correct.

    Thank you for your help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How do I tell WordPress a page is an archive?’ is closed to new replies.