I’m slightly PHP-illiterate (I’m getting better) but I’m having trouble with this one thing in particular. I’m trying to make my very first post on the first page a FULL post (no excerpt, and no thumbnail). After that very first post, I want the rest to be excerpts WITH a thumbnail post (aligned left, 100x100pixels). Can anyone help me out?
Here is what I have on content.php:
<?php
/**
* @package Spirit
* @since Spirit 1.0
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h7 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( '%s', 'spirit' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h7>
</header><!-- .entry-header -->
<table>
<tbody>
<tr>
<td>
<footer class="entry-meta2" align="left" title="<?php the_time('g:i A, T') ?>">
<?php if ( 'post' == get_post_type() ) : ?>
<?php the_time('l') ?><BR><?php the_time('M jS Y') ?>
<?php endif; ?>
<?php if ( ! post_password_required() && ( comments_open() || '0' != get_comments_number() ) ) : ?>
</footer>
<footer class="entry-meta4" align="left">
<span class="comments-link"><?php comments_popup_link( __( '0 Comments', 'spirit' ), __( '1 Comment', 'spirit' ), __( '% Comments', 'spirit' ) ); ?></span>
<?php endif; ?>
</footer>
<footer class="entry-meta3" align="left" title="category">
<?php
/* translators: used between list items, there is a space after the comma */
$category_list = get_the_category_list( __( ', ', 'spirit' ) );
if ( ! spirit_categorized_blog() ) {
// This blog only has 1 category so we just need to worry about tags in the meta text
if ( '' != $tag_list ) {
$meta_text = __( '<br> tags: %2$s<br><a href="%3$s" title="Permalink to %4$s" rel="bookmark">Permalink</a>', 'spirit' );
} else {
$meta_text = __( '<a href="%3$s" title="Permalink to %4$s" rel="bookmark">Permalink</a>.', 'spirit' );
}
} else {
// But this blog has loads of categories so we should probably display them here
if ( '' != $tag_list ) {
$meta_text = __( '%1$s <br> tags: %2$s<br><a href="%3$s" title="Permalink to %4$s" rel="bookmark">Permalink</a>', 'spirit' );
} else {
$meta_text = __( ' %1$s', 'spirit' );
}
} // end check for categories on this blog
printf(
$meta_text,
$category_list,
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
); ?>
</footer>
<footer class="entry-meta-two" title="tag"><?php echo get_the_tag_list('<p><i class="fa fa-tags"></i> ',', ','</p>'); ?></footer>
<footer class="entry-meta" align="left">
<?php edit_post_link( __( '(Edit)', 'spirit' ), '<span class="edit-link">', '</span>' ); ?>
</footer><!-- .entry-meta -->
</td>
<td>
<?php if ( is_search() ) : // Only display Excerpts for Search ?>
<div class="entry-summary">
<?php $excerpt = strip_tags(get_the_excerpt());
echo $excerpt; ?>
</div><!-- .entry-summary -->
<?php else : ?>
<div class="entry-content">
<?php the_post_thumbnail(); ?> <?php $excerpt = strip_tags(get_the_excerpt());
echo $excerpt; ?>
<?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'spirit' ), 'after' => '</div>' ) ); ?>
</div><!-- .entry-content -->
<?php endif; ?>
</td>
</tr>
</tbody>
</table>
<!-- .entry-meta -->
</article><!-- #post-<?php the_ID(); ?> -->
Here’s whats in my index.php:
<?php
/**
* The main template file.
*
* This is the most generic template file in a WordPress theme
* and one of the two required files for a theme (the other being style.css).
* It is used to display a page when nothing more specific matches a query.
* E.g., it puts together the home page when no home.php file exists.
* Learn more: http://codex.wordpress.org/Template_Hierarchy
*
* @package Spirit
* @since Spirit 1.0
*/
get_header(); ?>
<div id="primary" class="content-area">
<div id="content" class="site-content" role="main">
<?php if ( have_posts() ) : ?>
<?php spirit_content_nav( 'nav-above' ); ?>
<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php spirit_content_nav( 'nav-below' ); ?>
<?php else : ?>
<?php get_template_part( 'no-results', 'index' ); ?>
<?php endif; ?>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
The relevant parts in your content.php are those lines:
As you’re not in search mode, the part that is being used on index.php is the
else
condition. To remove the post thumbnail, just removethe_post_thumbnail()
, and to get the content instead of the excerpt usethe_content()
. This is what it should look (updated to affect only the first post of the loop):And in index.php, add this line just before the loop:
I’d do it like this:
You’ll need to create a
content_first.php
file and there style your first post, and the rest should be displayed usingcontent.php
template.