我有一个 wordpress
博客,其首页显示最新10篇文章的列表。
现在每当我点击任何文章标题时,都会在同一标签页中打开一个新文章,但我想让它在新标签页中打开。那么我该如何做呢?
< 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>
编辑您的主题
/wp-content/themes/your-theme-name/loop.php
查找文章链接,例如...
<a href="<?php the_permalink(); ?>" class="read_more_link" ><?php echo __('Read more »'
添加target="_blank"
属性
<a href="<?php the_permalink(); ?>" target="_blank" class="read_more_link" ><?php echo __(
href="<?php the_permalink(); ?>"
,这是每篇文章的永久链接。打开相关的php
文件,例如front-page.php
,home.php
等,在标题<a>
中添加target="_blank"
即可。
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>
除非您自己托管,否则我认为您无法这样做,否则只需将链接更改为:
<a href="your url" target="_blank">blah</a>