WordPress插件,可将前一篇文章的链接插入post_content

时间:2018-08-26 14:31:57

标签: wordpress

Wordpress插件,它在post_content中插入上一篇文章的链接,我做不到,我已经按照论坛中讲授的所有方法进行操作,在堆栈中我得到了几种,但是总是插入指向相同内容的链接今天发布!该链接仅将用户带到同一当前帖子!好像我通过单击链接刷新页面一样,我做了一个插件,将人员带到帖子的类别页面,但这对SEO不利。所以我需要建立到帖子的链接。

<?php
/*
Plugin name: HAW ADD URL POST CONTENT
Plugin URI: https://mywebsite.com
Description: This is a plugin to auto inser internal link to post_content(READ THE README.TXT) 
*/
add_filter( 'wp_insert_post_data' , 'add_string_on_publish_link' , '999', 3 );
function add_string_on_publish_link( $data,  $postarr='' ){
....... codes
$myvalueX = "{$arr[0]} {$arr[1]} {$arr[2]}";
$tag = "{$arr[0]} {$arr[1]}";
$tagX = implode('-',explode(' ', $tag));
$urlsite = site_url();
$bar = '/';
//THE_ARIAN BEGIN
//$prev_post = previous_post_link( '%link', __( '&larr; %title', 'text-domain' ) );

//$prev_post = get_adjacent_post(false, '', true);
//if(!empty($prev_post)) {
//$prevpost = '<a href="' . get_permalink($prev_post->ID) . '" title="' . $prev_post->post_title . '">' . $prev_post->post_title . '</a>'; }

  //$prevpost = previous_post_link( '%link');

    //$prevpost = previous_post_link( '%link', TRUE); 

  //$prevpost = get_previous_post('%link');

  //$prevpost= get_previous_posts_link();

  //$prevpost = get_previous_posts_page_link();
//THE_ARIAN END
$urlcatbase = get_option( 'category_base' );
$urlcatbaseX = "<a href=".$urlsite.$bar.$urlcatbase.$bar.$tagX.">".$tag."</a>";
//$urltagbaseX = "<a href=".$prevpost.">".$tag."</a>";   //THE_ARIAN
 $data['post_content'] .= "<p>{$data['post_title']} {mycontent}{$urlcatbaseX}</p>";
$data['post_content'] = preg_replace('/[\s]{1,}/',' ', $data['post_content']);
.......codes
}

感谢您的帮助

1 个答案:

答案 0 :(得分:0)

我不知道您的代码应该做什么,但是有一个专用功能可以获取以前的帖子链接:

get_previous_posts_link

您可以这样使用它:

echo get_previous_posts_link('Prev post or any other label');