这将有助于包括更多关于手头问题的信息。以及解释您取得或尝试的任何进展,以及您可能遇到困难的任何特定领域。这将允许其他人更好地帮助解决问题。
通过检查您使用的主题,我了解到这是基于genesis框架构建的子主题。至于增加特色帖子下方每个帖子的摘录长度,可以在wordpress管理面板的genesis framework自定义选项下的面板中进行设置:
添加特色帖子有点复杂,这取决于你的专业水平。请注意,我不熟悉genesis框架,也不是专家,只是想帮忙,希望您会发现这很有用。请不要认为这是一个最终的解决方案,但也许对我进一步了解这个主题很有用。
实现这一点的“一个”方法是创建一个自定义帖子循环,如果特色帖子始终是最新的帖子,为了不在第二个循环中重复帖子,将偏移1。请注意注释,这些注释为代码的每个部分提供了想法。将此代码粘贴到主题函数的底部。php文件。
//function to control excerpt word count for featured post
function feat_excerpt($limit) {
$excerpt = explode(\' \', get_the_excerpt(), $limit);
if (count($excerpt) >= $limit) {
array_pop($excerpt);
$excerpt = implode(" ", $excerpt) . \'...\';
} else {
$excerpt = implode(" ", $excerpt);
}
$excerpt = preg_replace(\'`\\[[^\\]]*\\]`\', \'\', $excerpt);
return $excerpt;
}
//custom loop for featured post
function featured_custom_loop() {
global $post;
// arguments, adjust as needed
$args = array(
\'post_type\' => \'post\',
\'posts_per_page\' => 1,
\'post_status\' => \'publish\',
\'paged\' => get_query_var( \'paged\' )
);
/*
Overwrite $wp_query with our new query.
The only reason we\'re doing this is so the pagination functions work,
since they use $wp_query. If pagination wasn\'t an issue,
use: https://gist.github.com/3218106
*/
global $wp_query;
$wp_query = new WP_Query( $args );
if ( have_posts() ) :
echo \'<div class="entry">\';
while ( have_posts() ) : the_post();
echo \'<h2 class="entry-title" style="" >\' . get_the_title() . \'</h2>\';
echo \'<div class = "entry-meta" style="">\'.genesis_post_info().\'</div>\';
echo \'<div class="entry-content" style=" word-wrap: break-word;">\' . feat_excerpt(155) . \'</div></br>\' ;
echo \'<div style=""><a href="\' . get_permalink() . \'" class="more-link button arrow-right" >READ MORE</a></div></div>\';
endwhile;
echo \'</div>\';
endif;
wp_reset_query();
}
///////////////////////// offset rest of the posts
function myprefix_query_offset(&$query) {
//Before anything else, make sure this is the right query...
if ( ! $query->is_main_query() ) {
return;
}
$offset = 1 ;
//Next, determine how many posts per page you want (we\'ll use WordPress\'s settings)
$ppp = get_option(\'posts_per_page\');
//Next, detect and handle pagination...
if ( $query->is_paged ) {
//Manually determine page query offset (offset + current page (minus one) x posts per page)
$page_offset = $offset + ( ($query->query_vars[\'paged\']-1) * $ppp );
//Apply adjust page offset
$query->set(\'offset\', $page_offset );
}
else {
//This is the first page. Just use the offset...
$query->set(\'offset\',$offset);
}
}
add_action(\'pre_get_posts\', \'myprefix_query_offset\', 1 );
add_filter(\'found_posts\', \'myprefix_adjust_offset_pagination\', 1, 2 );
function myprefix_adjust_offset_pagination($found_posts, $query) {
//Define our offset again...
$offset = 1;
//Ensure we\'re modifying the right query object...
if ( $query->is_posts_page ) {
//Reduce WordPress\'s found_posts count by the offset...
return $found_posts - $offset;
}
return $found_posts;
}
现在连接到genesis\\u before\\u循环,以加载我们的自定义特色的\\u custom\\u循环。在您的主题文件夹中,我们可以找到首页。php。在博客部分的打开标记部分中,查找行add\\u action(\'genesis\\u before\\u loop\')的位置,并在下面添加此行:
添加\\u操作(“genesis\\u before\\u loop”、“featured\\u custom\\u loop”);
请注意,这只是一个示例,但远不是最佳解决方案,请将此示例作为进一步学习的手段。希望有一位经验更丰富的开发人员可以补充这一点。
请注意以下链接,因为它们详细说明了与您试图实现的目标类似的过程:
资料来源:
www.steckinsights.com/offset-posts-genesis-framework-without-losing-pagination
http://genesisdictionary.com