【问题标题】:Help a newbie with a PHP Function用 PHP 函数帮助新手
【发布时间】:2010-04-10 20:10:12
【问题描述】:

我想使用这个功能:

http://www.frankmacdonald.co.uk/php/post-to-wordpress-with-php.html

它以前使用 XMLRPC 发布到 Wordpress,谁能给我使用这个功能的基础知识,或者简要介绍一下?

我想了解函数的工作原理以及如何使用它们。

编辑:

下面的指南就像做梦一样。

我想使用 foreach 循环循环浏览多个条目并将它们全部发布到 WP,不知道是否有人可以建议?

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    如果您想发布多个项目,那么每个帖子只有几处会发生变化:

    • 帖子的标题。
    • 帖子内容
    • 帖子的类别
    • 关键字(可选,但我猜你正在使用它)。

    RPC URL、用户名、密码和编码是标准的,因为我还假设您将其发布到同一个网站上。所以我们只需要将 4 个命名项存储在一个可以运行的数组中。我将项目存储在另一个数组中,所以我们有一个数组数组。

    你可以很容易地写出这样的东西:

    // We create a post array that contains an array per post.
    // I put in the data index based. First item is title, second is content body, third is category, fourth is keywords.
    $posts = array(
        array('Title','Contents','category','keywords'),
        array('Another post','More content','another category ID','etc.'),
        // You can add more items if you want.
    );
    
    // These are just general settings that are the same for each post.
    $rpcurl = 'http://www.yourwordpressblog.com/xmlrpc.php'; 
    $username = 'myusername'; 
    $password = 'mypassword'; 
    $encoding ='UTF-8';
    
    foreach($posts AS $Post)
    {
        // From the foreach we get an array with post data each cycle.
        // To keep things a bit clear, I will extract the data to seperate variables..
        $title = $Post[0];
        $body = $Post[1];
        $category = $Post[2];
        $keywords = $Post[3];
    
        wpPostXMLRPC($title,$body,$rpcurl,$username, $password,$category,$keywords,$encoding); 
    }
    

    【讨论】:

    • 是的,当然在这个网站上。我也在其他(荷兰)论坛上闲逛了很长时间。
    【解决方案2】:

    这里没什么可做的,它已经准备好运行了。

    只需替换第一行中给出的示例值:

    $title = 'This is the post title'; 
    $body = 'this is the post content'; 
    $rpcurl = 'http://www.yourwordpressblog.com/xmlrpc.php'; 
    $username = 'myusername'; 
    $password = 'mypassword'; 
    $category = ''; //default is 1, enter a number here. 
    $keywords = 'one,two,three';//keywords comma seperated. 
    $encoding ='UTF-8';//utf8 recommended 
    

    带有一些实际数据。 (如果您的博客位于根目录,则 xmlrpc.com 的链接应为 www.yourdomain.com/xmlrpc.php。)

    把整个东西放到一个 PHP 文件中,然后运行它。如果你幸运的话,一切都会在第一次运行时运行良好。如果没有,请返回并编辑您的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多