是否有一种方法可以实现具有双内容区域的单循环。
E.g. A single loop having 2 of
<?php the_content(); ?>
Dinstinguished as shown bellow with video and write-up respectively
<?php the_content(\'video\'); ?>
<?php the_content(\'write-up\'); ?>
是否有一种方法可以实现具有双内容区域的单循环。
E.g. A single loop having 2 of
<?php the_content(); ?>
Dinstinguished as shown bellow with video and write-up respectively
<?php the_content(\'video\'); ?>
<?php the_content(\'write-up\'); ?>
让我们首先从一点知识库开始:the_content
是这个吗
/**
* Display the post content.
*
* @since 0.71
*
* @param string $more_link_text Optional. Content for when there is more text.
* @param bool $strip_teaser Optional. Strip teaser content before the more text. Default is false.
*/
function the_content( $more_link_text = null, $strip_teaser = false) {
$content = get_the_content( $more_link_text, $strip_teaser );
$content = apply_filters( \'the_content\', $content );
$content = str_replace( \']]>\', \']]>\', $content );
echo $content;
}
有关content 是否生成检查:get_the_content()
所以video
和write-up
将是$more_link_text
在<a href="...">$more_link_text</a>
content
你有你想要的信息filtered (分开/分开)在两个区域执行此操作:add_filter(\'the_content\', \'filter_only_video\')
the_content();
remove_filter(\'the_content\', \'filter_only_video\');
add_filter(\'the_content\', \'filter_only_write\')
the_content();
remove_filter(\'the_content\', \'filter_only_write\');
并且在functions.php
添加以下内容:function filter_only_video($content) {
// your code that only keeps that video part on (removing the rest)
return $content;
}
function filter_only_write($content) {
// your code that only keeps write-up part on (removing the rest)
return $content;
}
如果正确编写这两个函数,可以在两个单独的位置显示所需的内容。查看中的默认214主题代码index.php
<?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;
// Previous/next post navigation.
twentyfourteen_paging_nav();
else :
// If no content, include the "No posts found" template.
get_template_part( \'content\', \'none\' );
endif;
?>
上述代码使用get_template_part();
我相信这就是你想要做的。我正在为每个width=\"*\" 宽度=“730px”且每height=\"*\"高度=“846”function replace_content_on_the_fly($text){ $replace = array( // \'words to find\' => \'replace with this\' \'width=\"*\"\' => \'width=\"730px\"\', \'heigh