【问题标题】:Change the order of title and featured image in Wordpress twenty twelve theme excerpt在 Wordpress 二十十二主题摘录中更改标题和特色图像的顺序
【发布时间】:2017-12-01 09:38:39
【问题描述】:

当我有一个显示帖子摘要的页面时,项目的顺序如下:

  1. 没有链接的特色图片
  2. 标题
  3. 总结

我想要的是

  1. 标题
  2. 带链接的特色图片
  3. 总结

当我查看主题代码 (content.php) 时,我遇到了一个名为 the_excerpt() 的函数。我在主题中找不到此功能,因此无法更新它。

<?php if ( is_search() || is_home() || is_tag() ) : // Only display Excerpts for Search ?>
    <div class="entry-summary">
        <?php the_excerpt(); ?>
    </div><!-- .entry-summary -->

所以我的问题是

  1. 有没有办法更改此主题中标题和特色图片的顺序?
  2. 如何将帖子链接添加到特色图片,以便读者点击图片时,他们会登陆帖子。

【问题讨论】:

  • 应该有一个名为archive.php的文件看一下...
  • 我添加了我拥有的代码,它在 content.php 中。我在archive.php 中找不到任何相关内容。
  • 摘录只是创建,嗯,帖子本身的摘录,它与特色图片或标题无关。查看摘录函数调用,您应该会找到它们(查找;the_title()the_post_thumbnail()
  • 哦,你的第二个问题;使用get_permalink()
  • 感谢您的回答。我得到了链接和正确的顺序。现在,我正在处理 css。

标签: php wordpress


【解决方案1】:

您必须移动“碎片”并添加一些 CSS 以使其看起来不错。

archive.php - 将header 标记的内容(以及标记本身)替换为以下代码:

    <header class="entry-header">
        <?php if ( is_single() ) : ?>
        <h1 class="entry-title"><?php the_title(); ?></h1>
        <?php else : ?>
        <h1 class="entry-title">
            <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
        </h1>
        <?php endif; // is_single() ?>

        <?php if ( ! post_password_required() && ! is_attachment() && !is_single() ) : ?>
            <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a>
        <?php endif; ?>
        <?php if ( comments_open() ) : ?>
            <div class="comments-link">
                <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentytwelve' ) . '</span>', __( '1 Reply', 'twentytwelve' ), __( '% Replies', 'twentytwelve' ) ); ?>
            </div><!-- .comments-link -->
        <?php endif; // comments_open() ?>
    </header><!-- .entry-header -->

请注意,您必须在 .entry-title 中添加一些样式,因为它下面没有间距,而且看起来不太好。

【讨论】:

  • 我必须将 && !is_single() 添加到 if 之前的 the_post_thumbnail() 并将永久链接添加到它周围的 href。出于某种原因,这段代码在 content.php 的 22 中。不是我必须调整css才能使间距正确。不幸的是,我不能赞成你的回答,因为我的分数低于 15。
猜你喜欢
  • 2015-11-29
  • 2015-05-26
  • 1970-01-01
  • 1970-01-01
  • 2013-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-02
相关资源
最近更新 更多