好的,我被要求修复一个有点奇怪的网站上的问题。索引页(template magazine.php)here, 有以下代码位:
<?php get_template_part(\'loop\'); ?>
要生成最新新闻的列表/网格,这里一切正常,每个条目都由时间、地点和事件描述片段表示。
单击一个类别时,称为归档。phpexample 和存档。php具有相同的调用:
<?php get_template_part(\'loop\'); ?>
构建事件列表/网格。但现在输出的是时间和地点,与以前一样,但代码片段也包括时间和日期。
现在我要提到的是,显示的帖子是一个来自于“一体式”活动日历的自定义帖子类型(通过及时发布)。这个问题可能与此有某种联系,但我是一个能理解这一点的wordpress noob。
自定义帖子类型添加到循环中,如下所示:
add_filter(\'pre_get_posts\', \'query_post_type\');
function query_post_type($query) {
if(is_category() || is_home() || is_tag() && empty( $query- >query_vars[\'suppress_filters\'] )) {
if ( empty($query->query_vars[\'post_type\']) ) {
$query->query_vars[\'post_type\'] = array(\'post\',\'ai1ec_event\');
} elseif ( \'any\' == $query->query_vars[\'post_type\'] ) {
return;
} else {
$query->query_vars[\'post_type\'] = (array)$query->query_vars[\'post_type\'];
$query->query_vars[\'post_type\'][] = \'ai1ec_event\';
}
}
}
希望有人能给我指出正确的方向。
这里是循环的内容。php:
<?php if ( have_posts() ) : ?>
<div class="loop">
<div id="loop" class="<?php if ($_COOKIE[\'mode\'] == \'grid\' ) echo \'grid\'; else echo \'list\'; ?> clear">
<?php
$postedon_data = array(
\'date\' => get_option(\'unspoken_postedon_date\'),
\'category\' => get_option(\'unspoken_postedon_cat\'),
\'comment\' => get_option(\'unspoken_postedon_comm\'),
\'author\' => get_option(\'unspoken_postedon_author\')
);
$i = 0;
while ( have_posts() ) : the_post();
$i++;
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(\'clear\'); ?>>
<a href="<?php the_permalink(); ?>" class="post-thumb"><?php if ( has_post_thumbnail() ) the_post_thumbnail(\'general\'); ?></a>
<div class="post-meta"><?php if (function_exists(\'unspoken_posted_on\')) unspoken_posted_on($postedon_data); ?></div>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>
<p><?php the_excerpt(); ?></p>
</div>
<?php
if ( $i % 2 == 0 ) echo \'<div class="clear"></div>\';
endwhile; // end of the loop.
?>
<div class="grid-line"></div>
</div><!-- #loop -->
</div><!-- .loop -->
<?php else : ?>
<div class="loop">
<div id="post-0" class="post hentry error404 not-found clear">
<h2><?php _e( \'Not found\', \'unspoken\' ); ?></h2>
<p><?php _e( \'Apologies, but no results were found for the requested criteria. Perhaps searching will help find a related post.\', \'unspoken\' ); ?></p>
</div><!-- #post-0 -->
</div>
<?php endif; ?>
添加我能找到的对摘录有帮助的所有过滤器:
主题/潜台词/功能。php
// Custom excerpt for comments
function unspoken_excerpt($string, $limit) {
$more = \'\';
$words = explode(" ",$string);
if ( count($words) >= $limit) $more = \'...\';
$output = strip_tags( implode(" ",array_splice($words, 0, $limit)).$more );
echo $output;
}
// Custom excerpt more
function unspoken_excerpt_more($more) {
return \'...\';
}
add_filter(\'excerpt_more\', \'unspoken_excerpt_more\');
function unspoken_excerpt_length($length) {
return 33;
}
add_filter(\'excerpt_length\', \'unspoken_excerpt_length\');
插件只有一个空函数。php似乎是以MVC为模型的。插件文件事件摘录。php具有以下功能:
<div class="timely ai1ec-excerpt">
<div class="ai1ec-time">
<strong><?php _e( \'<!--:es-->Fecha<!--:--><!--:ca-->Data<!--:--><!--:en-->Date<!--:-->:\', AI1EC_PLUGIN_NAME ); ?></strong>
<?php echo $event->get_timespan_html(); ?>
</div>
<?php if ( $location ) : ?>
<div class="ai1ec-location">
<strong><?php _e( \'<!--:es-->Lugar<!--:--><!--:ca-->Lloc<!--:--><!--:en-->Venue<!--:-->:\', AI1EC_PLUGIN_NAME ); ?></strong>
<?php echo $location; ?>
</div>
<?php endif; ?>
</div>
在另一个名为class-ai1ec-events-controller的插件文件中发现了一些有趣的东西。php
/**
* event_excerpt function
*
* Overrides what wp_trim_excerpt() returned if the post is an event,
* and outputs better rich-text (but not too rich) excerpt instead.
*
* @return void
**/
function event_excerpt( $text )
{
global $ai1ec_view_helper,
$ai1ec_events_helper;
if ( get_post_type() != AI1EC_POST_TYPE ) {
return $text;
}
$event = new Ai1ec_Event( get_the_ID() );
ob_start();
$this->excerpt_view( $event );
// Re-apply any filters to the post content that normally would have been
// applied if it weren\'t for our interference (below).
echo shortcode_unautop( wpautop(
$ai1ec_events_helper->trim_excerpt(
apply_filters( \'the_content\', $event->post->post_content )
)
) );
$page_content = ob_get_contents();
ob_end_clean();
return $page_content;
}
/**
* event_excerpt_noautop function
*
* Conditionally apply wpautop() filter to content, only if it is not an
* event.
*
* @return void
**/
function event_excerpt_noautop( $content ) {
if ( get_post_type() != AI1EC_POST_TYPE ) {
return wpautop( $content );
}
return $content;
}
在/model/class-ai1ec-event中找到此项。php
/**
* Get excerpt of post content for display in popup view
*/
public function get_post_excerpt() {
if (
! isset( $this->post->post_excerpt ) ||
empty( $this->post->post_excerpt )
) {
$content = strip_tags(
strip_shortcodes(
apply_filters( \'the_content\', $this->post->post_content )
)
);
$content = preg_replace( \'/\\s+/\', \' \', $content );
$words = explode( \' \', $content );
if ( count( $words ) > 25 ) {
$this->post->post_excerpt = implode(
\' \',
array_slice( $words, 0, 25 )
) . \' [...]\';
} else {
$this->post->post_excerpt = $content;
}
}
return $this->post->post_excerpt;
}
这就是我在摘录中所能找到的全部内容,希望能有所帮助。