【发布时间】:2018-05-11 01:27:58
【问题描述】:
是的,我知道以前有人问过这个问题,并且我尝试了其他帖子提供的各种解决方案,但没有成功。我希望让我最近的帖子显示全部内容,然后其余的只显示摘录。出于某种原因,counter++ 和 first 方法不起作用。我正在使用 Design Lab 的 Type Theme。
这是我的 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.
*
* @link https://codex.wordpress.org/Template_Hierarchy
*
* @package Type
* @since Type 1.0
*/
get_header(); ?>
<?php
/* Blog Options */
$blog_layout = get_theme_mod('blog_layout', 'list');
$blog_sidebar_position = get_theme_mod('blog_sidebar_position', 'content-sidebar');
$post_template = type_blog_template();
$post_column = type_blog_column();
?>
<?php if ( have_posts() ) : ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<section class="row posts-loop <?php if ('grid' == $blog_layout) { echo esc_attr('flex-row'); } ?>">
<?php /* Start the Loop */
while ( have_posts() ) : the_post(); ?>
<div class="post-wrapper <?php echo $post_column; ?>">
<?php get_template_part( 'template-parts/post/content', $post_template ); ?>
</div>
<?php endwhile; ?>
</section>
<?php the_posts_navigation(); ?>
</main><!-- #main -->
</div><!-- #primary -->
<?php else : ?>
<?php get_template_part( 'template-parts/post/content', 'none' ); ?>
<?php endif; ?>
<?php
// Sidebar
if ( 'content-sidebar' == $blog_sidebar_position || 'sidebar-content' == $blog_sidebar_position ) {
get_sidebar();
}
?>
<?php get_footer(); ?>
这是我的 content-list.php(我的主题是从中提取的):
" >
<?php if ( has_post_thumbnail() ) { ?>
<figure class="entry-thumbnail">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
<?php the_post_thumbnail('type-medium'); ?>
</a>
</figure>
<?php } ?>
<div class="entry-header">
<?php if ( 'post' === get_post_type() ) { ?>
<div class="entry-meta">
<span class="cat-links"><?php the_category( ', ' ); ?></span>
<span class="sep">/</span>
<?php echo '<span class="posted-on">' . type_time_link() . '</span>'; ?>
</div>
<?php } ?>
<h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
</div><!-- .entry-header -->
<div class="entry-summary">
<?php the_excerpt(); ?>
</div><!-- .entry-content -->
我知道我需要更改 the_excerpt(); to the_content();,但我不能让它只在最近的帖子上工作,而且任何时候我试图把计数器的代码放在我认为是循环开始的地方......我得到一个语法错误。
我更喜欢 html 和 css……但我掌握了 php 的基础知识……我只是……是的,我在这方面失败了。
谢谢!
【问题讨论】: