如何更改search.php中的结果内容?

时间:2016-10-27 09:15:38

标签: php wordpress wordpress-theming custom-wordpress-pages

Hello Wordpress People,

我想问一下如何在<div class="entry"><?php the_content(); ?></div>部分下面的代码中更改搜索结果的输出?

我只想显示页面,帖子或类别标题和文本。但Text也只有500个Charaters才能显示,然后链接“阅读更多”。

有没有办法完成这项工作?谢谢你的帮助。

这是我的search.php代码:

<div id="main">
    <?php if (have_posts()) : ?>
        <p class="info">Ihre Suchergebnisse f&uuml;r: <strong><?php echo $s ?></strong></p>

        <?php while (have_posts()) : the_post(); ?>
            <h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
            <div class="entry">
                <?php the_content(); ?>
            </div>
        <?php endwhile; ?>

        <p align="center"><?php next_posts_link('&laquo; &Auml;ltere Eintr&auml;ge') ?> | <?php previous_posts_link('Neuere Eintr&auml;ge &raquo;') ?></p>

    <?php else : ?>
        <div class="no-found">
            <h3>Ups?! Wir konnten unter dem Begriff <span>"<?php echo $s ?>"</span> leider nichts finden.</h3>
            <p>Kehren Sie bitte <a href="<?php bloginfo( 'url' ); ?>">zur Startseite</a> zurück.</p>
        </div>

    <?php endif; ?>
</div><!-- main -->

<div id="sidebar">
    <?php get_sidebar(); ?>
</div><!-- sidebar -->

2 个答案:

答案 0 :(得分:0)

我可能只是将the_content()更改为the_excerpt()。这将使您非常接近您想要的。

答案 1 :(得分:0)

你应该使用the_content的the_excerpt()函数,并使用更多的链接(永久链接)。

这里是代码:

{{1}}

另外,您可以按照此问题回答here

谢谢