如何列出我在WordPress博客上发布的所有外部URL?

时间:2014-03-21 作者:Nadeem Khan

我想在一个地方/文件中列出我帖子的所有外部链接。我怎样才能做到这一点?

是否可以通过插件实现这一点?

有没有可能通过内置的wordpress api实现这一点?

有没有可能通过一些免费的第三方工具来实现这一点?

要实现这一目标,应采取什么方法?

2 个回复
最合适的回答,由SO网友:pennstump 整理而成

当我想解析每个页面时,上面的代码都有分页问题。因此,在上述基础上,再加上一个kicker来搜索没有“nofollow”属性的链接,我得出了以下结论:

<ol>
<?php 

global $post;

//Write Site URL below.
//Don\'t write http:// or anything like that. just domain.com or domain.net
$_site_url = \'google.com\';

$args = array(
    \'posts_per_page\'   => 9999999999,
    \'offset\'           => 0,
    \'category\'         => \'\',
    \'category_name\'    => \'\',
    \'orderby\'          => \'ID\',
    \'order\'            => \'DESC\',
    \'include\'          => \'\',
    \'exclude\'          => \'\',
    \'meta_key\'         => \'\',
    \'meta_value\'       => \'\',
    \'post_type\'        => \'post\',
    \'post_mime_type\'   => \'\',
    \'post_parent\'      => \'\',
    \'author\'       => \'\',
    \'author_name\'      => \'\',
    \'post_status\'      => \'publish\',
    \'suppress_filters\' => true 
);
$myposts = get_posts( $args );
foreach( $myposts as $post ) : setup_postdata($post); 

  //Get Post content
  $_post_content =  get_the_content();

  $site_parts = explode(\'.\',$_site_url);
  $site_suffix = \'.\'.$site_parts[1];

  //Using regular expression to match hyperlink
  preg_match_all(\'|<a.*(?=href=\\"([^\\"]*)\\")[^>]*>([^<]*)</a>|i\', $_post_content, $match);

  foreach($match[0] as $link){
    //Filtering out internal links
    $parts = explode($site_suffix, $link);
    $domain = explode(\'//\',$parts[0]);
    //echo $domain[1];
    if ($domain[1] != \'www.\'.$site_parts[0] && $domain[1] != $site_parts[0] && strpos($link, \'nofollow\') === FALSE){
        echo \'<li><a href="\'.get_permalink($post->ID) . \'">\' . get_the_title() .\'</a>,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\'. $link.\'</li>\';
    }
  }

endforeach;
wp_reset_postdata(); 

?>
</ol>

SO网友:Sudeep K Rana

使用名称链接创建页面。Pages >> Add New 进入wordpress面板。随便说说links 并发布。见下文。

enter image description here

现在转到主题文件夹wp-content\\themes\\YOUR_ACTIVE_THEME_FOLDER 并创建一个页面page-links.php.

并将此代码粘贴到page-links.php

<?php  

$the_query = new WP_Query(array(\'post_type\' => \'post\'));
while($the_query->have_posts()):
    $the_query->the_post();
    $_post_id = get_the_id();

//Write Site URL below.
//Don\'t write http:// or anything like that. just domain.com or domain.net
$_site_url = \'google.com\';

//Getting Post content
$_post_content =  get_post_field( \'post_content\', $_post_id);


$site_parts = explode(\'.\',$_site_url);
$site_suffix = \'.\'.$site_parts[1];
//Using regular expression to match hyperlink
preg_match_all(\'|<a.*(?=href=\\"([^\\"]*)\\")[^>]*>([^<]*)</a>|i\', $_post_content, $match);

foreach($match[0] as $link){
    //Filtering out internal links
    $parts = explode($site_suffix, $link);
    $domain = explode(\'//\',$parts[0]);
    //echo $domain[1];
    if ($domain[1] != \'www.\'.$site_parts[0] && $domain[1] != $site_parts[0]  ){
        echo $link.\'<br>\';
    }
}

endwhile;
    wp_reset_postdata();
?>
现在需要对上面的代码进行更改。

    //Write Site URL below.
//Don\'t write http:// or anything like that. just domain.com or domain.net
$_site_url = \'google.com\';
代替$_site_url = \'google.com\'; 编写自己的域。确保它没有www和http://

请看一下这一页。

注意:避免使用所有内部链接的页面,只有链接到外部站点的页面才可见

根据需要自定义代码。

结束

相关推荐

Change Taxonomy Permalinks

我有自定义帖子,我创建了一个显示所有自定义帖子的页面。示例:www.example.com/archive-page我想知道是否可以更改与此自定义帖子相关的类别和标签的永久链接。现在我有:www.example.com/my-custom-post-type-cats/my-category-1www.example.com/my-custom-post-type-tags/my-tag-1</我想要这样的东西:www.example.com/archive-page?category=1www.e