WordPress 编辑 php get_template_part() 和 get_post_format() 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10889132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WordPress editing php get_template_part() and get_post_format() function
提问by acctman
I want to load the post content only with no title, date, comment, etc info. Is there a way to grab the post only?
我只想加载没有标题、日期、评论等信息的帖子内容。有没有办法只抓取帖子?
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
<?php endif; ?>
回答by Melus
You can replace
你可以更换
<?php get_template_part( 'content', get_post_format() ); ?>
with
和
<?php get_template_part( 'content', 'myformat' ); ?>
and edit a copy of content-page.phpwith name content-myformat.phpwhere you can remove the_title()row.
并编辑content-page.php带有名称的副本content-myformat.php,您可以在其中删除the_title()行。
回答by Foxinni
Simply replace:
简单替换:
<?php get_template_part( 'content', get_post_format() ); ?>
With:
和:
<?php the_content(); ?>
The former is looking for something like content-status.phpor content-aside.phpor most likely, in the case of a plain old 'post', content.phpin your theme root.
前者正在寻找类似content-status.php或content-aside.php 的东西,或者最有可能的,在一个普通的旧“帖子”的情况下,你的主题根目录中的content.php。

