我在我的博客中使用通知栏,其中包含最新帖子的链接。问题是我每次发布内容时都必须手动更新它。有没有什么方法可以让博主在每次发布任何内容时自动设置该链接的网址?如何在博客中获取最新帖子的网址
1
A
回答
1
我们可以通过使用feed和JavaScript来实现这一点。代码将如下所示 -
<script>
function recentPostLink(posts){
var link = posts.feed.entry[0].link[4].href;
document.querySelector('.recent').href = link; // The class present on anchor tag
}
</script>
<script src='https://yourblogname.blogspot.com/feeds/posts/summary?alt=json&max-results=1&callback=recentPostLink' />
+1
这不行吗? 'document.querySelectorAll('。post a')[0] .href;' –
+0
它没有工作 –
+0
@AryanAnkitRaj您可以分享博客网址,您正在测试此代码吗? –
0
Blogger拥有精选的发布部件。前往布局>添加小工具>精选文章。你可以用它来展示最新帖子通过使如果你想使用JavaScript和JSON饲料使用最新发布后
,把下一个代码的链接元素
<script>
//<![CDATA[
function recent(json) {
var element = document.querySelector('.link');
element.innerHTML = json.feed.entry[0].title.$t;
element.href = json.feed.entry[0].link[4].href;
}
//]]>
</script>
<script src='/feeds/posts/default/?alt=json-in-script&callback=recent&max-results=1'/>
0
使用这个脚本后,到
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script><div id="recent-posts"><script language="JavaScript">
home_page = "Enter your blog url here";
numposts = 5;
imgr = new Array();showRandomImg = false;boxwidth = 255;cellspacing = 6;borderColor = "#232c35";bgTD = "#000000";thumbwidth = 0;thumbheight = 0;fntsize = 15;acolor = "#666";aBold = true;icon = " ";text = false;showPostDate = false;summaryPost = 0;summaryFontsize = 10;summaryColor = "#666";icon2 = " ";</script><script src="http://24work-new.googlecode.com/svn/trunk/24work-blogspot/recent-posts-t/recent-posts-min-1-ycode.js" type="text/javascript"/></script><link rel="stylesheet" type="text/css" href="http://24work-new.googlecode.com/svn/trunk/24work-blogspot/recent-posts-t/recent-posts-min-3.css" /></div>
它看起来像这样
相关问题
- 1. 博客页面=最新帖子在WordPress
- 2. 获取wordpress博客以外的最新帖子
- 3. 使用php xml获取博客最新帖子链接
- 4. WordPress - 在iframe中预览最新的wordpress博客帖子
- 5. Tumblr API - 如何使用NodeJS获取私人博客的帖子?
- 6. WordPress的博客文章的网址不重定向到帖子
- 7. 如何在wordpress中获取帖子的图片网址?
- 8. 为集合中的每个博客选择最新帖子
- 9. 抓取Blogger上未托管的博客帖子的第一个图像网址
- 10. 从wordpress获取最新博客文章
- 11. 如何从一个WordPress博客中提取“最近的帖子”数据?
- 12. 在博客帖子中使用变量
- 13. 如何从WordPress博客中以HTML的形式获取帖子的内容
- 14. 什么是在博客中存储帖子的最佳方式
- 15. 网址在博客中的Django
- 16. SilverStripe:最新博客帖子内容区域
- 17. 获取所有帖子,一个帖子,我的帖子等网址设计
- 18. 从iPhone获取最新的facebook帖子?
- 19. 如何在鬼博客的帖子中实现过滤器
- 20. 如何获取所有帖子和博客文章按类别在wordpress
- 21. 如何让Apache重写博客网址?
- 22. 如何在Android应用中从WordPress博客中检索帖子?
- 23. 如何从我的blogspot博客中列出所有帖子的帖子标题?
- 24. 在帖子博客上选择帖子类别的形式
- 25. wordpress中特定博客帖子/帖子的简码?
- 26. .htaccess代码将旧的博客网址重定向到一个新的域上的新博客网址
- 27. 如何使用Tumblr API V2获取特定博客的标记帖子?
- 28. 获取最新的帖子,然后在循环中的其他帖子 - Wordpress
- 29. Django的:获取所有博客和自己的最新博客文章
- 30. Magento 2. Aheadworks博客。帖子在主页
使用RSS,你会得到你博客的最新帖子 –
问题依然存在,如何? –