Skip to content

Commit

Permalink
update docs and readme examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jjgrainger committed May 11, 2022
1 parent 418655e commit 42cc368
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 34 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ require __DIR__ . '/vendor/autoload.php';

use PostTypes\PostType;

$books = new PostType('book');
$books = new PostType( 'book' );

$books->register();
```
Expand All @@ -44,6 +44,7 @@ require __DIR__ . '/vendor/autoload.php';

// Import PostTypes.
use PostTypes\PostType;
use PostTypes\Taxonomy;

// Create a book post type.
$books = new PostType( 'book' );
Expand Down
3 changes: 2 additions & 1 deletion docs/Getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require __DIR__ . '/vendor/autoload.php';

use PostTypes\PostType;

$books = new PostType('book');
$books = new PostType( 'book' );

$books->register();
```
Expand All @@ -40,6 +40,7 @@ require __DIR__ . '/vendor/autoload.php';

// Import PostTypes.
use PostTypes\PostType;
use PostTypes\Taxonomy;

// Create a book post type.
$books = new PostType( 'book' );
Expand Down
2 changes: 2 additions & 0 deletions docs/taxonomies/Columns.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
You can now modify `Taxonomy` columns using the same methods as you would for a `PostType`. For example:

```php
use PostTypes\Taxonomy;

// Create a taxonomy.
$genres = new Taxonomy( 'genre' );

Expand Down
16 changes: 8 additions & 8 deletions docs/taxonomies/Create-a-taxonomy.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ To create a new taxonomy pass the taxonomy name to the class constructor. Labels
use PostTypes\Taxonomy;

// Create a new taxonomy
$genres = new Taxonomy('genre');
$genres = new Taxonomy( 'genre' );

// Register the taxonomy to WordPress
$genres->register();
Expand All @@ -28,7 +28,7 @@ $names = [
'slug' => 'genres'
];

$genres = new Taxonomy($names);
$genres = new Taxonomy( $names );

$genres->register();
```
Expand All @@ -51,19 +51,19 @@ $options = [
'hierarchical' => false,
];

$genres = new Taxonomy('genre', $options);
$genres = new Taxonomy( 'genre', $options );

$genres->register();
```

Alternatively, you can set options using the `options()` method.

```php
$genres = new Taxonomy('genre');
$genres = new Taxonomy( 'genre' );

$genres->options([
$genres->options( [
'hierarchical' => false,
]);
] );

$genres->register();
```
Expand All @@ -76,10 +76,10 @@ You can define the labels for a taxonomy by passing an array as the third argume

```php
$labels = [
'add_new_item' => __('Add new Genre'),
'add_new_item' => __( 'Add new Genre' ),
];

$genres = new Taxonomy('genres', $options, $labels);
$genres = new Taxonomy( 'genres', $options, $labels );

$genres->register();
```
Expand Down
48 changes: 24 additions & 24 deletions examples/books.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,54 @@
use PostTypes\Taxonomy;

// Create a books Post Type
$books = new PostType('book');
$books = new PostType( 'book' );

// Add the Genre Taxonomy
$books->taxonomy('genre');
$books->taxonomy( 'genre' );

// Hide the date and author columns
$books->columns()->hide(['date', 'author']);
$books->columns()->hide( [ 'date', 'author' ] );

// add a price and rating column
$books->columns()->add([
'rating' => __('Rating'),
'price' => __('Price')
]);
$books->columns()->add( [
'rating' => __( 'Rating' ),
'price' => __( 'Price' )
] );

// Populate the custom column
$books->columns()->populate('rating', function($column, $post_id) {
echo get_post_meta($post_id, 'rating') . '/10';
});
$books->columns()->populate( 'rating', function( $column, $post_id ) {
echo get_post_meta( $post_id, 'rating' ) . '/10';
} );

// Populate the custom column
$books->columns()->populate('price', function($column, $post_id) {
echo '£' . get_post_meta($post_id, 'price');
});
$books->columns()->populate( 'price', function( $column, $post_id ) {
echo '£' . get_post_meta( $post_id, 'price' );
} );

// Set sortable columns
$books->columns()->sortable([
'price' => ['price', true],
'rating' => ['rating', true]
]);
$books->columns()->sortable( [
'price' => [ 'price', true ],
'rating' => [ 'rating', true ]
] );

// Set the Books menu icon
$books->icon('dashicons-book-alt');
$books->icon( 'dashicons-book-alt' );

// Register the PostType to WordPress
$books->register();

// Create the genre Taxonomy
$genres = new Taxonomy('genre');
$genres = new Taxonomy( 'genre' );

// Add a popularity column to the genre taxonomy
$genres->columns()->add([
$genres->columns()->add( [
'popularity' => 'Popularity'
]);
] );

// Populate the new column
$genres->columns()->populate('popularity', function($content, $column, $term_id) {
return get_term_meta($term_id, 'popularity', true);
});
$genres->columns()->populate( 'popularity', function( $content, $column, $term_id ) {
return get_term_meta( $term_id, 'popularity', true );
} );

// Register the taxonomy to WordPress
$genres->register();

0 comments on commit 42cc368

Please sign in to comment.