【发布时间】:2014-07-31 08:26:42
【问题描述】:
我在 WordPress 中使用以下 PHP 将不同的类应用于我主页上的帖子,具体取决于它们的位置:
<article id="post-<?php the_ID(); ?>"
<?php
$extra = ( ( $wp_query->current_post % 5 == 0 && !is_page() ) ? 'full' : 'half' ) . ( ( ( $wp_query->current_post % 5 == 1 || $wp_query->current_post % 5 == 3 ) && !is_page() ) ? ' left' : '' );
post_class($extra);
?>>
在我的functions.php中,我使用以下内容来更改这些帖子的摘录长度:
function twentytwelvechild_custom_excerpt_length( $length ) {
global $wp_query;
if( $wp_query->current_post%5 == 0 ) return 30;
else return 12;
}
add_filter( 'excerpt_length', 'twentytwelvechild_custom_excerpt_length', 12 );`
这使得每 5 个帖子的第一个帖子的摘录长度为 30,其余 12 个,但我不想这样做。
如何使用 PHP 将 'full' 类的文章的摘录长度更改为 30 个单词,将半个类的文章的摘录长度更改为 12 个单词?
希望这是有道理的
詹姆斯
【问题讨论】:
-
php是什么意思?期望的输出是什么?请准确。你的问题没有意义
标签: wordpress