2017 © Pedro Peláez
 

library corcel

Wrappers to collect data from Wordpress databases

image

rajivseelam/corcel

Wrappers to collect data from Wordpress databases

  • Thursday, July 10, 2014
  • by rjvim
  • Repository
  • 2 Watchers
  • 5 Stars
  • 67 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 268 Forks
  • 0 Open issues
  • 2 Versions
  • 2 % Grown

The README.md

Wordpress Corcel

This package helps you integrate wordpress with your laravel installation., (*1)

Let's say you dropped your wordpress at public/wordpress and http://xyz.com/wordpress open wordpress blog. But, may be, may be for some crazy reason you want use your Laravel routes and controllers to show off the blog, let's say at http://xyz.com/blog! This way you can control the look, add blogs to any other pages, access that database all the while using wordpress admin., (*2)

Of course you can use Raw DB Statements to do this! But, What's fun in that! Corcel gives you Eloquent Classes to do that!, (*3)

Corcel is under development., (*4)

Credit goes to Junior Grossi for starting this!, (*5)

I have extended some of the functionality., (*6)

--, (*7)

Corcel is a class collection created to retrieve Wordpress database data using a better syntax. It uses the Eloquent ORM developed for the Laravel Framework, but you can use Corcel in any type of PHP project., (*8)

This way you can use Wordpress as back-end, to insert posts, custom types, etc, and you can use what you want in front-end, like Silex, Slim Framework, Laravel, Zend, or even pure PHP (why not?)., (*9)

Installation

To install Corcel just create a composer.json file and add:, (*10)

"require": {
    "rajivseelam/corcel": "dev-master"
},

Include the following in your public/index.php (So that we can WP functions), (*11)

define('WP_USE_THEMES', false);
require __DIR__.'/wordpress/wp-blog-header.php';

After that run composer install and wait., (*12)

Connecting to DB

You needn't do this if you are using WP along with Laravel., (*13)

First you must include the Composer autoload file., (*14)

require __DIR__ . '/vendor/autoload.php';

Now you must set your Wordpress database params:, (*15)

$params = array(
    'database'  => 'database_name',
    'username'  => 'username',
    'password'  => 'pa$$word',
);
Corcel\Database::connect($params);

You can specify all Eloquent params, but some are default (but you can override them)., (*16)

'driver'    => 'mysql',
'host'      => 'localhost',
'charset'   => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix'    => '',

Usage

Posts

// All published posts
$posts = Post::published()->get();
$posts = Post::status('publish')->get();

// A specific post
$post = Corcel\Post::find(31);
echo $post->post_title;

// A specific post by slug
$post = Corcel\Post::slug($slug)->first();

You can retrieve meta data from posts too., (*17)

// Get a custom meta value (like 'link' or whatever) from a post (any type)
$post = Corcel\Post::find(31);
echo $post->meta->link; // OR
echo $post->link;

//Categories or Tags of a post
$post->categories(); 

$post->tags();

//Get thumbnail url
$post->thumbnail_url();

//Get the large version
$post->thumbnail_url('large');

//Find posts under a category

$category = Corcel\Category::where('slug',$slug)->first();

$posts = $category->posts();


//Find posts under a tag

$tag = Corcel\Tag::where('slug',$slug)->first();

$posts = $tag->posts();

Categories and Tags

// Get all categories

$categories = Corcel\Category::all();

Custom Post Type

You can work with custom post types too. You can use the type(string) method or create your own class., (*18)

// using type() method
$videos = Post::type('video')->status('publish')->get();

// using your own class
class Video extends Corcel\Post
{
    protected $postType = 'video';
}
$videos = Video::status('publish')->get();

Custom post types and meta data., (*19)

// Get 3 posts with custom post type (store) and show its title
$stores = Post::type('store')->status('publish')->take(3)->get();
foreach ($stores as $store) {
    $storeAddress = $store->address;
}

Pages

Pages are like custom post types. You can use Post::type('page') or the Page class:, (*20)

// Find a page by slug
$page = Page::slug('about')->first(); // OR
$page = Post::type('page')->slug('about')->first();
echo $page->post_title;

More

Dig through the code to find more!, (*21)

Licence

Corcel is licensed under the MIT license., (*22)

The Versions

10/07 2014

dev-master

9999999-dev http://github.com/rajivseelam/corcel

Wrappers to collect data from Wordpress databases

  Sources   Download

MIT

The Requires

 

27/06 2014

dev-add_tags_categories_to_post

dev-add_tags_categories_to_post http://github.com/rajivseelam/corcel

Wrappers to collect data from Wordpress databases

  Sources   Download

MIT

The Requires