wordpress搜索页面内容在哪里生成?
我正在尝试在wordpress中设置搜索页面的样式。在search.php中,我可以设置页面的大部分样式,但是下面的语句(我从原始未编辑页面获得)生成了内容。wordpress搜索页面内容在哪里生成?,wordpress,search,Wordpress,Search,我正在尝试在wordpress中设置搜索页面的样式。在search.php中,我可以设置页面的大部分样式,但是下面的语句(我从原始未编辑页面获得)生成了内容。 <?php /* Include the Post-Format-specific template for the content. * If you want to overload this in a child
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
这是可行的…但它并没有显示太多内容,因为我不知道在看到原文时在我的页面中放什么
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
有人有任何线索吗?您可以使用名为
post search.php的模板部分,并可以在您的search.php文件中使用它,如
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
get_template_part( 'post' , 'search')
但是你必须在你的主题文件夹中创建一个php文件,并将其命名为post search.php
,然后在这个文件中放入WordPress'循环,即
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php while (have_posts()) : the_post(); ?>
<div class="post-entry clearfix"> <!-- Main wrapper -->
<div class="post-entry-content"> <!-- Post-entry-content -->
<h2><a href="<?php the_permalink(' ') ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
<div class="post-entry-date">Posted on <?php the_time('F Y') ?> with <?php comments_popup_link('0 Comments', '1 Comment', '% Comments'); ?></div>
<?php the_excerpt(); ?>
<a href="<?php the_permalink(' ') ?>" class="post-entry-read-more" title="<?php the_title(); ?>">Read More ?</a>
</div><!-- END of post-entry-content -->
</div><!--End of main wrapper -->
<?php endwhile; ?>
张贴于
您的search.php可能是这样的
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php get_header(' '); ?>
<div id="post-wrap">
<div id="post-content">
<?php if (have_posts()) : ?>
<?php get_template_part( 'post' , 'search') ?> // This will load/include the file post-search.php and result will be displayed as formatted in this file
<?php else : ?>
<p>Sorry, it does not exist !</p>
<?php endif; ?>
</div><!-- END post-conten -->
<?php get_sidebar(' '); ?>
</div><!-- END post-wrap -->
<?php get_footer(' '); ?>
//这将加载/包括post-search.php文件,结果将显示为该文件中的格式
对不起,它不存在
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
这只是一个例子,根据主题css更改div/h2 id/类名
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
注意:我目前在我的一个网站上使用这种方法,在我的主题文件夹和每个模板文件(index.php、search.php e.t.c)中有一个名为“post entry.php”的文件,我只需调用
<?php
/* Include the Post-Format-specific template for the content.
* If you want to overload this in a child theme then include a file
* called content-___.php (where ___ is the Post Format name) and that will be used instead.
*/
get_template_part( 'content', get_post_format() );
?>
<?php endwhile; ?>
<?php get_template_part( 'post' , 'entry') ?>
Bingo!谢谢,这就解决了。我所做的唯一不同的事情是使用content-search.php,但它做的事情是相同的:)现在我知道了所有东西的来源,我可以让它看起来很漂亮:P