Jquery、Cookie 和 Blogger
在我的 Blogger 博客上,我的模板中有此代码
<b:if cond='data:blog.pageType == "index"'>
<b:else/>
<p><data:post.body/></p>
</b:if>
此代码基本上仅在博客文章位于单个博客页面上时才显示博客文章的正文。
您可以在此处查看示例 www.spoilertv.com 当您位于主页时,仅显示帖子标题。单击标题即可查看完整帖子。
我想做的是让博客的读者选择是否在主页上显示帖子正文
我想要一个简单的单选按钮或复选框,我可以将其放置在博客上,例如“显示完整内容”。默认情况下此功能处于关闭状态。如果用户单击它,我们就会使用 Jquery 设置 cookie,然后重新加载页面。
使用 cookie 后,如果用户稍后返回该站点,它会记住他们的偏好并相应地显示。
上面的代码需要更新,以便它检查 cookie 的值,如果它设置为完整内容,那么它就会显示。伪代码是这样的。
<b:if cond='data:blog.pageType == "index"'>
if cookie is set to full content then
<p><data:post.body/></p>
endif
<b:else/>
<p><data:post.body/></p>
</b:if>
如果有人可以帮助我完成这个小项目,我将非常感激。
预先感谢您的任何帮助。
On my Blogger Blog I have this code in the template
<b:if cond='data:blog.pageType == "index"'>
<b:else/>
<p><data:post.body/></p>
</b:if>
This code basically shows the body of the blog post only when it's on an individual blog page.
You can see an example here www.spoilertv.com When you are on the homepage only the post title is displayed. Clicking on the title gives you the full post.
What I would like to do is to give the reader of the blog the choice of if the Body of the Post is displayed or not on the homepage
I would like a simple radio button or checkbox that I can place on the blog something like "Show Full Content". This is turned off by default. If the user clicks it, we then set a cookie using Jquery and we then reload the page.
The cookie would be used so that if the user returns to the site later it would remember their preference and display accordingly.
The code above would need to be updated so that it checksthe value of the cookie and if it's sets to Full Content then it would display. Pseudo code something like this.
<b:if cond='data:blog.pageType == "index"'>
if cookie is set to full content then
<p><data:post.body/></p>
endif
<b:else/>
<p><data:post.body/></p>
</b:if>
If anyone can help me with this little project I would be very grateful.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我是一名 WordPress 开发人员,所以对 blogger 不太熟悉,但无论如何都会尽力帮助你。
如果 blogger 与 WP 类似,那么隐藏或显示页面上已生成的内容就不是问题了。 (这就是 JQ 会为您做的)。您的第一步是显示内容。
我知道这可以在博客中完成 - 这是一个示例:
http://photographybyspandan.blogspot.com/
另外在这里做了一个测试帖子: http://siberianx37thoughts.blogspot.com/
我认为这是一个设置您可以在博客中设置显示完整的帖子标题。
然后,您可以编辑模板,并将帖子包装在元素中。在本例中它是 p,因此只需向其添加一个特定的类即可。然后使用 jquery 隐藏/显示该元素
http://www.learningjquery .com/2006/09/basic-show-and-hide
您也可以使用 firebug for firefox 来帮助您:)
I'm a wordpress dev, so not too familiar with blogger, but will try to help you out anyways.
If blogger is similar to WP, then it's not a matter of hiding or showing the content that's already being generated on the page. (which is what JQ would do for you). Your first step is to get the content to show up.
And i know it can be done in blogger - here's an example:
http://photographybyspandan.blogspot.com/
plus did a test post here: http://siberianx37thoughts.blogspot.com/
I think it's a setting you can set in blogger to display full post title.
Then, you can edit the template, and wrap the post in an element. In this case it's p so just add a specific class to it. then use jquery to hide / show that element
http://www.learningjquery.com/2006/09/basic-show-and-hide
You can use firebug for firefox to help you too :)