Php Wordpress:使第一篇文章完整,而留下其余的摘录(带缩略图!)

Php Wordpress:使第一篇文章完整,而留下其余的摘录(带缩略图!),php,wordpress,thumbnails,Php,Wordpress,Thumbnails,我有点不懂PHP(我正在进步),但我在这一点上遇到了麻烦。我试图使我在第一页上的第一篇文章成为一篇完整的文章(没有摘录,也没有缩略图)。在第一篇文章之后,我希望剩下的是一篇缩略文章的摘录(左对齐,100x100像素)。有人能帮我吗 以下是我在content.php上的内容: <?php /** * @package Spirit * @since Spirit 1.0 */ ?> <article id="post-<?php the_ID(); ?>" <

我有点不懂PHP(我正在进步),但我在这一点上遇到了麻烦。我试图使我在第一页上的第一篇文章成为一篇完整的文章(没有摘录,也没有缩略图)。在第一篇文章之后,我希望剩下的是一篇缩略文章的摘录(左对齐,100x100像素)。有人能帮我吗

以下是我在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(); ?> -->
<?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(); ?>


content.php中的相关部分如下所示:

<?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; ?>
在index.php中,在循环前添加以下行:

<?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; ?>
<?php /* Start the Loop */ ?>
<?php $first = true; ?>
<?php while ( have_posts() ) : the_post(); ?>

content.php中的相关部分如下:

<?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; ?>
在index.php中,在循环前添加以下行:

<?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; ?>
<?php /* Start the Loop */ ?>
<?php $first = true; ?>
<?php while ( have_posts() ) : the_post(); ?>

我会这样做:

<div id="primary" class="content-area">
    <div id="content" class="site-content" role="main">

    <?php $i = 0; 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.
                 */
                if ($i = 0) {
                    get_template_part( 'content_first', get_post_format() );
                    $i++;
                } else{
                    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 -->

您需要创建一个
content\u first.php
文件,并在其中设置您的第一篇文章的样式,其余内容应使用
content.php
模板显示。

我会这样做:

<div id="primary" class="content-area">
    <div id="content" class="site-content" role="main">

    <?php $i = 0; 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.
                 */
                if ($i = 0) {
                    get_template_part( 'content_first', get_post_format() );
                    $i++;
                } else{
                    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 -->



你需要创建一个
content\u first.php
文件,然后在那里设置你的第一篇文章的样式,其余的应该使用
content.php
模板来显示。

我认为你在这个模板上乱动不会有什么运气。您需要找到
index.php
,并将主查询所在的部分发布出来。然后我们可以看到这些帖子发生了什么。此外,你应该找到一个更好的杂志主题,这是真的过时了,并没有更新自2013年以来。我的意思是,谁再使用表格来设计页面样式??哦,谢谢你的快速回复!即使在2013年,我也在index.php..@dingo_d中包含了我的内容,这是不可接受的。但不幸的是,很多WP主题(甚至是流行的主题)都是由那些不关心SEO/可访问性的人制作的。我不认为你会在这个模板上多管闲事。您需要找到
index.php
,并将主查询所在的部分发布出来。然后我们可以看到这些帖子发生了什么。此外,你应该找到一个更好的杂志主题,这是真的过时了,并没有更新自2013年以来。我的意思是,谁再使用表格来设计页面样式??哦,谢谢你的快速回复!即使在2013年,我也在index.php..@dingo_d中包含了我的内容,这是不可接受的。但不幸的是,很多WP主题(甚至是流行的主题)都是由那些不关心SEO/可访问性的人制作的。。。不完全是我想要的。。。我想保留缩略图,但仅限于摘录。我希望第一页的第一篇文章是没有缩略图的完整文章,尽管…@RoseannaOverstreet啊,我不明白这一点。请给我一点时间编辑我的答案。@RoseannaOverstreet查看更新的答案。我为循环的第一个post添加了一个条件。您还需要更新index.php,以便在循环开始之前添加
$first
布尔值。好的,我在index.php中添加了所需的内容,并将条目内容下的内容更改为如下所示:
但不知何故,缩略图仍然没有显示在摘录中…您使用的条件错误-如果
$first
为false,则需要显示缩略图/摘录,并使用
内容()。看看我如何在回答中使用条件。好的。。。不完全是我想要的。。。我想保留缩略图,但仅限于摘录。我希望第一页的第一篇文章是没有缩略图的完整文章,尽管…@RoseannaOverstreet啊,我不明白这一点。请给我一点时间编辑我的答案。@RoseannaOverstreet查看更新的答案。我为循环的第一个post添加了一个条件。您还需要更新index.php,以便在循环开始之前添加
$first
布尔值。好的,我在index.php中添加了所需的内容,并将条目内容下的内容更改为如下所示:
但不知何故,缩略图仍然没有显示在摘录中…您使用的条件错误-如果
$first
为false,则需要显示缩略图/摘录,并使用
内容()。看看我在回答中是如何使用条件的。我是像这样发布content_first.php:
还是必须在那行代码之前加上一些东西?在
content_first.php
中,你可以随心所欲地设计你的第一篇文章;)我是这样发布content\u first.php:
还是必须在那行代码之前加上一些东西?在
content\u first.php
中,您可以按照自己喜欢的方式设计第一篇文章的风格;)