自动获取评论者网站最新文章
这个想法又是老郑提出的,这件事比较囧,由于我怕网上已经有人已经写过类似的文章,所以搜了一下,居然搜到老郑自己的...不过那个方法是用commentLUV这个插件,此插件并非自动显示,而是需要评论者自己勾选然后手动添加到评论内容中, 所以我就觉得这篇文章可以写了
这个想法又是老郑提出的,这件事比较囧,由于我怕网上已经有人已经写过类似的文章,所以搜了一下,居然搜到老郑自己的...不过那个方法是用commentLUV这个插件,此插件并非自动显示,而是需要评论者自己勾选然后手动添加到评论内容中,
所以我就觉得这篇文章可以写了.下图是鼠标移到评论者昵称上的效果:

判断网址有效性
CP党和小白白们可以无视这段,直接看二三小节.
这个问题我单独拎出来,用来判断feed地址是否能正常访问,因为如果不能访问,会出现parse_url的WP_ERROR,导致后面的元素都停止加载,解决方法是用PHP的get_headers()
函数,如果HTTP返回参数200说明网页能正常访问,代码如下:
$uri='XXX'; $array = get_headers($uri,1); if(preg_match('/200/',$array[0]))//说明能正常访问
hover效果
在functions.php中找到类似这样的句子
%s'), get_comment_author_link()) ?>
改成
<?php printf(__('<span class="rss"><cite class="fn">%s</cite>'), get_comment_author_link()) ?> <!--这里放下一节的的正式代码完整版本-->
然后加上css
.comment-author .rss div{display: none;position:absolute;background:#fff;border:1px solid #bbb;padding:10px;top:30px;left:50px} .comment-author .rss:hover div{display:block}
完整代码
此段代码应该放在comments的Loop内
<?php if(current_user_can('level_10')){//只对管理员显示,如果想对所有人显示,请去掉此行和最后一个} //但是请注意:抓取他站feed会严重拖慢你的网速,尤其是遇到feed无效时,建议只对管理员显示;异步加载大神可无视 $uri =get_comment_author_url().'/feed';//获取评论者网址,一般而言"网址/feed"是网站feed的地址 $match1 = '/http/';//无网址游客生成的comment_author_url中没有http if( preg_match_all($match1, $uri, $match) ){//如果填写了网址则开始抓feed $array = get_headers($uri,1); //判断网址有效性 if(preg_match('/200/',$array[0])){ //如果网址有效 $feed = fetch_feed($uri); if(! is_wp_error($feed)) { $items = $feed->get_items(0,1); //1可以改成你想抓取的文章数 echo '<div>';//如果没有使用第二节的hover效果,此行可去掉 if ( $items == 0 ) { echo '没有发现文章'; } foreach($items as $item) { echo '<a rel="nofollow" target="_blank" href="'.%24item->get_link().'">'.$item->get_title().'</a>'.$item->get_date('Y-m-j G:i').'<br>'; } echo '</div>';//如果没有使用第二节的hover效果,此行可去掉 } } } } ?>
改变feed缓存
wordpress默认对fetch_feed抓取的结果启用12小时的缓存,若要改变此时间,在functions.php中加入以下代码
function new_feed_cache( $seconds ) { return 3600;//单位为秒,3600代表一小时,其他以此类推 } add_filter( 'wp_feed_cache_transient_lifetime' , 'new_feed_cache' );
原文地址:自动获取评论者网站最新文章, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Websites for learning C language: 1. C Language Chinese Website; 2. Rookie Tutorial; 3. C Language Forum; 4. C Language Empire; 5. Script House; 6. Tianji.com; 7. Red and Black Alliance; 8, 51 Self-study network; 9. Likou; 10. C Programming. Detailed introduction: 1. C language Chinese website, which is a website dedicated to providing C language learning materials for beginners. It is rich in content, including basic grammar, pointers, arrays, functions, structures and other modules; 2. Rookie tutorials, This is a comprehensive programming learning website and more.

Google Authenticator is a tool used to protect the security of user accounts, and its key is important information used to generate dynamic verification codes. If you forget the key of Google Authenticator and can only verify it through the security code, then the editor of this website will bring you a detailed introduction on where to get the Google security code. I hope it can help you. If you want to know more Users please continue reading below! First open the phone settings and enter the settings page. Scroll down the page and find Google. Go to the Google page and click on Google Account. Enter the account page and click View under the verification code. Enter your password or use your fingerprint to verify your identity. Obtain a Google security code and use the security code to verify your Google identity.

In macOS Sonoma and Safari 17, you can turn websites into "web apps," which can sit in your Mac's dock and be accessed like any other app without opening a browser. Read on to learn how it works. Thanks to a new option in Apple's Safari browser, it's now possible to turn any website on the internet you frequently visit into a standalone "web app" that lives in your Mac's dock and is ready for you to access at any time. The web app works with Mission Control and Stage Manager like any app, and can also be opened via Launchpad or SpotlightSearch. How to turn any website into

If you are using a Linux operating system and want the system to automatically mount the drive on boot, you can do this by adding the device's unique identifier (UID) and mount point path to the fstab configuration file. fstab is a file system table file located in the /etc directory. It contains information about the file systems that need to be mounted when the system starts. By editing the fstab file, you can ensure that the required drives are loaded correctly every time the system starts, thus ensuring stable system operation. Automatically mounting drivers can be conveniently used in a variety of situations. For example, I plan to back up my system to an external storage device. To achieve automation, ensure that the device remains connected to the system, even at startup. Likewise, many applications will directly

Although the general operations of domestic mobile phones are very similar, there are still some differences in some details. For example, different mobile phone models and manufacturers may have different dual-SIM installation methods. Erzhenwo 12Pro, a new mobile phone, also supports dual-SIM dual standby, but how should dual-SIM be installed on this phone? How to install dual SIM on Realme 12Pro? Remember to turn off your phone before installation. Step 1: Find the SIM card tray: Find the SIM card tray of the phone. Usually, in the Realme 12 Pro, the SIM card tray is located on the side or top of the phone. Step 2: Insert the first SIM card. Use a dedicated SIM card pin or a small object to insert it into the slot in the SIM card tray. Then, carefully insert the first SIM card.

Preface: vim is a powerful text editing tool, which is very popular on Linux. Recently, I encountered a strange problem when using vim on another server: when I copied and pasted a locally written script into a blank file on the server, automatic indentation occurred. To use a simple example, the script I wrote locally is as follows: aaabbbcccddd. When I copy the above content and paste it into a blank file on the server, what I get is: aabbbcccddd. Obviously, this is what vim does automatically for us. Format indentation. However, this automatic is a bit unintelligent. Record the solution here. Solution: Set the .vimrc configuration file in our home directory, new

JavaScript tutorial: How to get HTTP status code, specific code examples are required. Preface: In web development, data interaction with the server is often involved. When communicating with the server, we often need to obtain the returned HTTP status code to determine whether the operation is successful, and perform corresponding processing based on different status codes. This article will teach you how to use JavaScript to obtain HTTP status codes and provide some practical code examples. Using XMLHttpRequest

If the "Get the latest updates as soon as they become available" option is missing or grayed out, you may be running a Developer Channel Windows 11 build, and this is normal. For others, issues arise after installing the KB5026446 (22621.1778) update. Here's what you can do to get back the "Get the latest updates as soon as they become available" option. How do I get the "Get the latest updates as soon as they're available" option back? Before starting any of the solutions below, make sure to check for the latest Windows 11 updates and install them. 1. Use ViVeTool to go to the Microsoft Update Catalog page and look for the KB5026446 update. Download and reinstall the update on your PC
