您应该能够通过两次调整来做到这一点。第一个将创建锚点,第二个将调整链接以使用锚点。
锚点可以引用为<a>
带有一个标签name
属性或几乎任何带有id
属性。我想说大多数 WordPress 主题已经有一个可以使用的锚点#content
。导航到您的任何博客文章并查看源代码。搜索id="content"
在源代码中并验证它是否存在。如果没有,请找一个id
您的实际帖子内容在哪里,您可以使用该内容。如果找不到,则需要创建一个。
在您的 WordPress 主题文件中,查找名为的文件single.php
。这通常是控制单个帖子呈现方式的文件。您将编辑此文件以添加锚点(如有必要)并调整链接。
如果您无法找到id
要使用(无论是“内容”还是其他任何内容),您需要找到调用内容进行输出的位置并添加id
到它周围的任何 HTML 标签。
例如,我的文件的精简版本如下所示:
<div id="primary">
<div id="content">
<?php while ( have_posts() ) : the_post(); ?>
<div class="entry-content">
<?php the_content(); // this is your post content ?>
</div><!-- .entry-content -->
<?php endwhile; // end of the loop. ?>
</div>
</div>
输出链接的方法有很多种,所以这实际上取决于主题和 WordPress 的版本。在里面single.php
文件中,查找与“next_post”和“previous_post”相关的函数。大多数用于创建链接的函数会自动写入整个链接标记(<a>
)为您服务,因此无法拦截链接并更改它。
您需要自己编写链接。下面的代码显示了如何获取信息并创建链接。它假设您将使用id="content"
作为您的锚参考。
<?php
$prev_post = get_previous_post();
if (!empty( $prev_post )): ?>
<a href="<?php echo get_permalink( $prev_post->ID ); ?>#content"><?php echo $prev_post->post_title; ?></a>
<?php endif; ?>
<?php
$next_post = get_next_post();
if (!empty( $next_post )): ?>
<a href="<?php echo get_permalink( $next_post->ID ); ?>#content"><?php echo $next_post->post_title; ?></a>
<?php endif; ?>
这应该会创建您正在寻找的链接,该链接会自动将页面跳转到图像和帖子内容。