如何在新标签页/窗口中打开每篇WordPress文章?

3

我有一个 wordpress 博客,其首页显示最新10篇文章的列表。

现在每当我点击任何文章标题时,都会在同一标签页中打开一个新文章,但我想让它在新标签页中打开。那么我该如何做呢?

6个回答

6
在WordPress中,每个主题都有不同的模板。
请尝试查找。
    < a href="<?php the_permalink(); ?>"...............><?php the_title(); ?></a>    

按下 F3 并搜索此代码,如 the_title();。通常这些类型的代码可以在模板文件中找到,例如:

single.php、content.php、loop.php、content-single.php

只需在该代码中添加 target="_blank"

例如:

<a href="<?php the_permalink(); ?>" target="_blank".....><?php the_title(); ?></a>

2

编辑您的主题

/wp-content/themes/your-theme-name/loop.php

查找文章链接,例如...

<a href="<?php the_permalink(); ?>" class="read_more_link" ><?php echo __('Read more &raquo;'

添加target="_blank"属性

<a href="<?php the_permalink(); ?>" target="_blank" class="read_more_link" ><?php echo __(

每个WordPress主题都有不同的HTML结构。只需搜索以下内容:href="<?php the_permalink(); ?>",这是每篇文章的永久链接。

谢谢,是的,我的主题没有loop.php文件,但the_permalink()函数在index.php中,所以我只需添加目标并且它正常工作。谢谢。 - Jeegar Patel

1

打开相关的php文件,例如front-page.phphome.php等,在标题<a>中添加target="_blank"即可。


0

一个方便的解决方法是在更新页面通知后将横幅设置为在新标签页中打开:页面已更新。 查看页面 链接。在 <a 调用之后添加 target="_blank"。 在文件 /wp-admin/edit-form-advanced.php 中,将第136行更改为图形所示。这是在WordPress v4.9.8中实现的。当WP更新时,可能需要再次进行修复。 突出显示添加文本的文本编辑器视图


0
I found this code on http://www.wpcodesnippet.com/open-external-links-new-window/ and it worked like a charm for me. Just add it to your footer.php.   

 <script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function($) {
            $('a').each(function() {
                var a = new RegExp('/' + window.location.host + '/');
                if(!a.test(this.href)) {
                    $(this).click(function(event) {
                        event.preventDefault();
                        event.stopPropagation();
                        window.open(this.href, '_blank');
                    });
                }
            });
        });
        //]]>
    </script>

1
嗨!你可以更新你的回答,包括来自链接的相关代码吗?如果该链接在未来失效,你的回答将变得无用。请参考http://stackoverflow.com/help/how-to-answer中的“为链接提供上下文”部分。 - Gustavo Straube

-1

除非您自己托管,否则我认为您无法这样做,否则只需将链接更改为:

<a href="your url" target="_blank">blah</a>

你需要编辑的文件应该是 wp-content/themes/YOUR_THEME/loop-page.php。它将是那些循环页面之一。 - r-sal

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接