用jQuery附加WordPress的帖子标题

编程入门 行业动态 更新时间:2024-10-25 12:28:53
本文介绍了用jQuery附加WordPress的帖子标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想通过jquery在选择器之后添加标题<?php the_title(); ?>

i want add the title <?php the_title(); ?> after my selector by jquery

('a img').after('<span>the title here</span>');

推荐答案

PHP代码在服务器上解释,而jQuery代码在浏览器中解释(在PHP解释器完成很长时间之后).他们真的看不见对方.

PHP code is interpreted on the server, jQuery code in the browser (long after the PHP interpreter has finished). They can't really see each other.

您可以做的是将the_title()的值放在页面上的某个元素中,然后使用jQuery找到并添加它:

What you can do is put the value of the_title() in some element on the page and then use jQuery to locate it and add it:

var title = $('#the_title').text(); $('a img').after('<span>' + title + '</span>');

如果您有多个标题,则必须以某种方式将它们映射到图像.有很多可能的方法可以做到这一点:

If you have several titles, then you must map them to the images somehow. There are many possible ways to do that:

  • 您可以将图像的名称发送到PHP服务器,让其查找标题并将其发送回.查找$().json().

您可以通过将所有标题包装在<div style="display: none;">中,将所有标题放在不可见的HTML中.然后,您可以在jQuery中将图像映射到标题.

You can put all the titles in some piece of HTML that you make invisible by wrapping it in <div style="display: none;">. In your jQuery, you can then map images to titles.

更多推荐

用jQuery附加WordPress的帖子标题

本文发布于:2023-10-12 17:28:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1485385.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标题   帖子   jQuery   WordPress

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!