admin管理员组文章数量:1331928
Current I have my search just return the title of the page that has the result, is there a way to show an excerpt
This is what i have
<?php get_header(); ?>
<section class="page-wrap">
<div class="container">
<div class="col-lg-9 section-space--ptb_30">
<?php
$s=get_search_query();
$args = array(
's' =>$s
);
// The Query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
_e("<h2 style='padding-bottom:20px;'>Search Results for '".get_query_var('s')."'</h2>");
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
}
}else{
?>
<h2 style='font-weight:bold;color:#000'>Nothing Found</h2>
<div class="alert alert-info">
<p>Sorry, but nothing matched your search criteria. Please try again with some different keywords.</p>
</div>
<?php } ?>
</div>
</div>
</section>
<?php get_footer(); ?>
Current I have my search just return the title of the page that has the result, is there a way to show an excerpt
This is what i have
<?php get_header(); ?>
<section class="page-wrap">
<div class="container">
<div class="col-lg-9 section-space--ptb_30">
<?php
$s=get_search_query();
$args = array(
's' =>$s
);
// The Query
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
_e("<h2 style='padding-bottom:20px;'>Search Results for '".get_query_var('s')."'</h2>");
while ( $the_query->have_posts() ) {
$the_query->the_post();
?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
}
}else{
?>
<h2 style='font-weight:bold;color:#000'>Nothing Found</h2>
<div class="alert alert-info">
<p>Sorry, but nothing matched your search criteria. Please try again with some different keywords.</p>
</div>
<?php } ?>
</div>
</div>
</section>
<?php get_footer(); ?>
Share
Improve this question
asked Jul 16, 2020 at 19:16
Milly RocMilly Roc
1
1 Answer
Reset to default 0Yes, you just have to call the function the_excerpt()
:
Right after …
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
… you add:
<div class="search-excerpt"><?php the_excerpt(); ?></div>
And then you can style it in your CSS file with:
.search-excerpt
{
/* some code */
}
本文标签: theme developmentIs it possible to show sort page excerpt in searchphp
版权声明:本文标题:theme development - Is it possible to show sort page excerpt in search.php 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742253392a2441178.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论