wordpress - wordpress 搜索页面内容在哪里生成?

标签 wordpress search

我正在尝试在 wordpress 中设置搜索页面的样式。在 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; ?>

这几乎显示了我想要的页面,但页面上有一些元素,使其展开等。我无法弄清楚生成此内容的文件!

使用说明我创建了一个 content-search.php 并将代码行更改为此...
get_template_part( 'content', get_post_format() );

哪个有效......但它没有显示任何内容,因为我不知道在看到原始内容的情况下在我的页面中放入什么。

有人有任何线索吗?

最佳答案

您可以使用名为 post-search.php 的模板部件。并且可以在您的 search.php 文件中使用它,例如

get_template_part( 'post' , 'search')

但是您必须在主题文件夹中创建一个 php 文件并将其命名为 post-search.php并在此文件中放置 WordPress 的循环,即
<?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 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(' '); ?>

这只是一个例子,根据你的主题 css 更改 div/h2 id/class 名称。

注:我目前正在我的一个站点中使用这种方法,并且在我的主题文件夹和我的每个模板文件(index.php、search.php 等)中有一个名为“post-entry.php”的文件,我只是使用它通过调用文件
<?php get_template_part( 'post' , 'entry') ?>

关于wordpress - wordpress 搜索页面内容在哪里生成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9873277/

相关文章:

javascript - Iframe 不尊重高度属性

css - 如何从 Wordpress 中的博客文章中删除弯 Angular

php - Woocommerce - 禁用变体选择时的图像更改

search - 如何构建搜索引擎? (2013 更新)

wordpress - 自定义 archive.php 页面中的分页

search - 反转文件与签名文件

batch-file - 递归搜索所有位置的特定文件,包括隐藏的批处理

python - 是否有 DolphinDB 函数用于查找向量中元素的索引?

search - 如何使用与 Solr 的 n-grams 近似匹配?

php - 插件系统如何工作(wordpress、mybb ...)?