我是WordPress主题开发的新手,我对如何将帖子显示到页面中有以下疑问。
我有这个页面属于一个旧的自定义遗留博客,我再次使用WordPress: http://www.asper-eritrea.com/comunicati.asp
你可以在这个页面上看到一些帖子使用以下结构:日期后面跟着帖子标题后面跟着简短摘要
我想在WordPress中做的就是这样。
所以我创建了这个页面来显示帖子列表:http://lnx.asper-eritrea.com/category/legacyposts/
你可以看到在这个页面上显示的帖子(格式是可怕的,因为我从旧网站导入的帖子,但我会在第二次工作)。
主要的问题是,如果文章很长,它会显示所有的内容。
这是本页的代码(category.php)是:
<?php get_header(); ?>
<!-- Contenuti (griglia) -->
<div class="container">
<!-- Lead presentazione -->
<section id="presentazione">
<div class="row">
<div class="col-sm-12">
<!--<h1 class="text-center"><small>Associazione per la Tutela dei Diritti Umani del Popolo Eritreo</small></h1>-->
<h1 class="text-center title">Associazione per la Tutela dei Diritti Umani del Popolo Eritreo</h1>
<h1 class="text-center leadTitle">Association in Defense of the Human Rights of the Eritrean People</h1>
<!--
<p class="lead text-center">
Association in Defense of the Human Rights of the Eritrean People
</p>
-->
</div><!-- /.col-sm-12 -->
</div><!-- /.row -->
</section><!-- /section presentazione -->
<!-- Progetti in evidenza -->
<header class="header-sezione">
<h2>Ultimi Articoli</h2>
</header>
<?
// get the term using the slug and the tag taxonomy
$term = get_term_by( 'slug', 'featured', 'post_tag' );
// pass the term_id to tag__not_in
query_posts( array( 'tag__not_in' => array ( $term->term_id )));
?>
<?php
if (have_posts()) :
// Start the Loop.
while (have_posts()) : the_post();
/*
* Include the post format-specific template for the content. If you want to
* use this in a child theme, then include a file called called content-___.php
* (where ___ is the post format) and that will be used instead.
*/
get_template_part('content', get_post_format());
endwhile;
else :
// If no content, include the "No posts found" template.
get_template_part('content', 'none');
endif;
?>
</section>
</div>
<?php get_footer(); ?>
所以我想做的是,对于每个帖子,循环只显示日期,标题和帖子的开头(例如特定的字符数)。
我怎么做才能得到这个结果?
Tnx
首先你应该开始阅读wordpress的代码,这样你就可以知道wordpress是如何工作的。
现在,category.php模板正在尝试用以下代码查找其他模板部分:
get_template_part("content", get_post_format());
这段代码寻找的是content-post format.php,如果这个文件不存在,wordpress会自动寻找content.php,而这个文件就是你要找的。
必须找到这个文件,并使用以下函数
the_excerpt();
get_the_date();
the_title()
现在,如果你想控制摘录的大小,你可以在function.php中使用这个函数。
function custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );