Git Product home page Git Product logo

zend-service-wordpress's Introduction

ZendX_Service_Wordpress

Similar to Zend_Service_Twitter, this service allows you to easily consume a WordPress blog's content via WordPress' XML-RPC gateway.

Usage

Zend_Service_Wordpress tries to keep a small, consistent API that returns results based on the context of the call.

For example, you can call getCategories() on both the ZendX_Service_Wordpress and ZendX_Service_Wordpress_Post.

With the first, you'll receive all of the categories for the entire blog while the latter returns only the categories attached to that post (as ZendX_Service_Wordpress_Category objects, of course).

Connect to your blog:

// ZendX_Service_Wordpress(XMLRPC_URL, USERNAME, PASSWORD[, CACHE = true ])
//
// Caching assumes that categories/posts/tags aren't being edited during the lifetime
// or the page rendering
$wordpress = new ZendX_Service_Wordpress('http://wordpress-site.com/xmlrpc.php', 'username', 'password');

// Get default blog
$blog = $wordpress->getBlog();
// or a specific blog by id:
$blog = $wordpress->getBlog(0)

Get various site information:

echo $blog->getTitle();         // My WordPress Blog
echo $blog->getDescription();   // Another WordPress Blog
echo $blog->getUrl();           // http://wordpress-site.com/
echo $blog->getLink();          // <a href="http://wordpress-site.com" title="My WordPress Blog">My WordPress Blog</a>
// etc...

List all tags:

foreach ($blog->getTags() as $tag) {
    // Uses ZendX_Service_Wordpress_Tag object
    echo sprintf('<a href="%s">%s</a>', $tag->getUrl(), $tag);
    // or
    echo $tag->getLink();
}

List all categories:

foreach ($blog->getCategories() as $category) {
    // Uses ZendX_Service_Wordpress_Category object
    echo sprintf('<a href="%s">%s</a>', $category->getUrl(), $category);
    // or
    echo $category->getLink();
}

Get recent posts

foreach ($blog->getRecentPosts(10) as $post) {
    // Uses ZendX_Service_Wordpress_Post object
    echo $post->getLink();
}

Get post information

echo $post->getTitle();
echo $post->getExcerpt();

echo $post->getBody();
// or
echo $post  // __toString method calls `getBody()`

foreach ($post->getTags() as $tag) {
    echo $tag->getLink();
}

foreach ($post->getCategories() as $category) {
    echo $category->getLink();
}

Unit Testing

You can perform unit testing by installing PHPUnit (I recommend the manual install) and doing...

# cd zend-service-wordpress/tests
# phpunit

Hopefully, you should see something like:

phpunit PHPUnit 3.3.9 by Sebastian Bergmann.

.......

Time: 18 seconds

OK (7 tests, 28 assertions)

If you want to run a specific test, simply run:

# phpunit --filter testTags.

However, if you want to run all tests for Wordpress in general (or perhaps a subset of tests for just Blog, Post, Category, Author, or Tag), simply run:

# phpunit --group Wordpress
# phpunit --group Blog
# phpunit --group Post
etc...

Code Sniffing

You can run PHP CodeSniffer to ensure your markup follows the Zend standard by running:

# cd zend-service-wordpress
# phpcs --report=full --standard=Zend .

zend-service-wordpress's People

Contributors

evank avatar trq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.