WordPress 发布到 Jquery 移动框架

发布于 2024-12-06 08:42:15 字数 658 浏览 1 评论 0原文

我想将我的 WordPress 帖子显示到 jquery 移动应用程序中...但到目前为止我还没有成功。我正在使用 jquery.post() 函数,但我的响应为空....

对所需网址的请求进展顺利,状态为 200 ok,但响应始终为空:( 尽管相同的 post 函数& url 在其他 php 页面中工作正常......

下面是我的代码

function get_Time(cityCode,date){
  jQuery.post(
    "http://test.local/time/", 
    { city: cityCode, date:date}, 
    function (data){jQuery('#print_time').html(data);}
    );

 }

function _get_Time(response)
{
    alert("response:"+response);
    var time = new Array();
    time = response.split('|')
    jQuery("#print_time").html(time[0]);
}

请给我一些解决方案,以将我的 WordPress 帖子(仅文本 + 链接)内容显示到我的 jquery 移动应用程序中......

I want to show my wordpress post into jquery mobile application... But so far i didnt got the success. I am using jquery.post() function but my response comes empty....

Request to the desired url goes well , status comes 200 ok but response coming is always blank :( Although the same post function & url is working fine in other php pages....

below is my code

function get_Time(cityCode,date){
  jQuery.post(
    "http://test.local/time/", 
    { city: cityCode, date:date}, 
    function (data){jQuery('#print_time').html(data);}
    );

 }

function _get_Time(response)
{
    alert("response:"+response);
    var time = new Array();
    time = response.split('|')
    jQuery("#print_time").html(time[0]);
}

Please give me some solution for showing my wordpress post (only text + links) content into my jquery mobile applicaton....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终弃我 2024-12-13 08:42:15

我不确定你要做什么。在我看来,就像您想通过 Ajax 检索某个 WordPress 帖子内容 + 附加信息一样,我认为最简单的方法如下:

  1. 编写一个自定义服务器端 PHP 脚本(这可能需要WordPress Slug 或 ID)

  2. 在此脚本中创建与数据库的连接,获取您想要的帖子内容并将它们作为文本或 JSON 返回到您的 JQuery 移动设备并使用 在此脚本中创建

它可能以如下方式工作(未测试):

include ‘path-to-wp-directory/wp-blog-header.php’;

$post_id=0;

if(isset($_REQUEST['post_id'])) {
$post_id=intval($_REQUEST['post_id']);
}

global $wpdb;

$post_content = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE post_id=".$post_id." AND post_status='publish'";

echo $post_content;

当然,这只有在您有权访问服务器的情况下才有可能。如果您想从外部 WordPress 博客获取帖子内容,那么您应该考虑使用 RSS Feed。

以下文章展示了如何在外部 PHP 脚本中加载 WordPress 函数,这也可能有用:

I am not sure about what you are going to do. It seems to me, like you want to retrieve a certain WordPress post content + additional information via Ajax, I think the easiest way to do it is the following:

  1. Write a custom server-side PHP-Script (which possibly takes a WordPress Slug or ID)

  2. Create a connection to the database in this script, get the post contents you want to have and return these as text or JSON to your JQuery mobile and use it

It might work in a way like this (not tested):

include ‘path-to-wp-directory/wp-blog-header.php’;

$post_id=0;

if(isset($_REQUEST['post_id'])) {
$post_id=intval($_REQUEST['post_id']);
}

global $wpdb;

$post_content = $wpdb->get_var("SELECT post_content FROM $wpdb->posts WHERE post_id=".$post_id." AND post_status='publish'";

echo $post_content;

This is only possible if you have access to the server, of course. If you want to get Post Content from an external WordPress Blog, then you should consider using the RSS Feed.

The following article shows how to load WordPress functions in an external PHP Script, which also might be useful: http://www.bloggingtips.com/2009/01/25/use-wordpress-functions-externally/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文