duanao2585 2015-11-09 14:03
浏览 49

Wordpress:让第一篇文章完整,同时留下其他摘录(缩略图!)

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(); ?>
  • 写回答

2条回答 默认 最新

  • doqrt26664 2015-11-09 14:50
    关注

    The relevant parts in your content.php are those lines:

    <?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; ?>
    

    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 remove the_post_thumbnail(), and to get the content instead of the excerpt use the_content(). This is what it should look (updated to affect only the first post of the loop):

    <?php else : ?>
        <div class="entry-content">
        <?php if(!$first): ?>
                <?php the_post_thumbnail(); ?> <?php $excerpt = strip_tags(get_the_excerpt());
                echo $excerpt; ?>
        <?php else: ?>
                <?php the_content(); $first = false; ?>
        <?php endif; ?>
        <?php wp_link_pages( array( 'before' => '<div class="page-links">' . __( 'Pages:', 'spirit' ), 'after' => '</div>' ) ); ?>
        </div><!-- .entry-content -->
    <?php endif; ?>
    

    And in index.php, add this line just before the loop:

    <?php /* Start the Loop */ ?>
    <?php $first = true; ?>
    <?php while ( have_posts() ) : the_post(); ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)