Skip to content

Commit

Permalink
Add information about shortcode and default connection name in README…
Browse files Browse the repository at this point in the history
… file
  • Loading branch information
jgrossi committed Jul 13, 2017
1 parent e59e0c2 commit eb19337
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ You can install WordPress inside Laravel's `/public` directory, like `/public/wo

## Laravel Setup

Corcel by default will look for a `wordpress` or `corcel` database connection in your Laravel `config/database.php` file. If it does not find any of these connections it'll use the `default` connection.

For example, you can have a `default` connection for your Laravel app tables and models, and another one called `wordpress` or `corcel` for your WordPress tables. Easy like that.
Just the the database `connection` you want to be used by Corcel. Let' suppose you have those following database connections in your `config/database.php` file:

```php
<?php // File: /config/database.php
Expand Down Expand Up @@ -93,6 +91,12 @@ For example, you can have a `default` connection for your Laravel app tables and
],
```

In this case you should want to use the `wordpress` connection for Corcel, so just set it into the Corcel config file `config/corcel.php`:

```php
'connection' => 'wordpress',
```

## Other PHP Framework (not Laravel) Setup

Here you have to configure the database to fit the Corcel requirements. First, you should include the Composer `autoload` file if not already loaded:
Expand Down Expand Up @@ -340,6 +344,39 @@ This is particular useful when you are intending to get a Collection of Posts of

## <a id="shortcodes"></a> Shortcodes

### From config (Laravel)

You can map all shortcodes you want inside the `config/corcel.php` file, under the `'shortocodes'` key. In this case you should create your own class that `implements` the `Corcel\Shortcode` interface, that requires a `render()` method:

```php
'shortcodes' => [
'foo' => App\Shortcodes\FooShortcode::class,
'bar' => App\Shortcodes\BarShortcode::class,
],
```

This is a sample shortcode class:

```php
class FakeShortcode implements \Corcel\Shortcode
{
/**
* @param ShortcodeInterface $shortcode
* @return string
*/
public function render(ShortcodeInterface $shortcode)
{
return sprintf(
'html-for-shortcode-%s-%s',
$shortcode->getName(),
$shortcode->getParameter('one')
);
}
}
```

### In runtime

You can add [shortcodes](https://codex.wordpress.org/Shortcode_API) by calling the `addShortcode` method on the `Post` model :

```php
Expand Down

0 comments on commit eb19337

Please sign in to comment.