是的,我知道之前已经问过这个问题,我尝试过其他帖子提供的各种解决方案,但没有成功 . 我希望我最近的帖子显示完整的内容,然后其余的只显示摘录 . 由于某种原因,计数器和第一种方法不起作用 . 我正在使用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的基础知识......我只是...是的,我失败了 .
谢谢!
3 回答
好的......所以...这里是我编辑index.php的地方......因为content-list.php工作正常......
好吧,是的,你看起来像是在正确的轨道上,但还没到那里 . 首先,您需要创建初始postcount并将其设置为0 .
所以在你的index.php中,这样做:
然后,在index.php中进一步向下,执行以下操作:
由于你的主题没有定义使用完整的帖子或只是在index.php中的摘录,就像上面链接的教程中的例子那样,你还需要改变别的东西 .
在你的content_list.php中,找到这个部分:
并将其更改为:
这应该是我认为的伎俩 .
我希望有所帮助 . 如果没有,请告诉我你得到了什么错误 .
给这篇文章一个读 - > https://www.nosegraze.com/featured-post-homepage/
你可以这样做的方法是寻找最新的帖子并使用the_content()进行显示;如果帖子不是最新的帖子,它应该显示the_excerpt .
希望这是有道理的 .
我以为我也会更新答案 . 看起来你实际上还没有找到最新的帖子,所以我真的很快就把一些东西放进去 . 它可能无法工作,因为我没有测试它,但你得到它的要点(哈)