From fd4f37f36010033ed5e2e10006e2c10b2c111269 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Tue, 1 Nov 2016 10:31:47 +0000 Subject: [PATCH] Add helper methods --- src/Providers/WordpressTemplatingServiceProvider.php | 4 ++-- src/Proxy/Query.php | 20 ++++++++++++++++++++ src/Support/Wordpress.php | 9 ++++----- src/helpers.php | 28 ++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/src/Providers/WordpressTemplatingServiceProvider.php b/src/Providers/WordpressTemplatingServiceProvider.php index 16a6f9e..7c3bf5f 100644 --- a/src/Providers/WordpressTemplatingServiceProvider.php +++ b/src/Providers/WordpressTemplatingServiceProvider.php @@ -19,8 +19,8 @@ class WordpressTemplatingServiceProvider extends ServiceProvider public function boot() { Blade::directive('loop', function () { - return ''; + return 'hasPosts()): while (query()->hasPosts()): ' + . 'query()->post(); $post = post(); ?>'; }); Blade::directive('endloop', function () { diff --git a/src/Proxy/Query.php b/src/Proxy/Query.php index a56650a..678648b 100644 --- a/src/Proxy/Query.php +++ b/src/Proxy/Query.php @@ -9,6 +9,26 @@ use WP_Query; /** * Proxies the {@link \WP_Query} class from Wordpress for a more elegant syntax. * + * @property array $query Query vars set by the user + * @property array $queryVars Query vars, after parsing + * @property \WP_Tax_Query $taxQuery Taxonomy query + * @property \WP_Meta_Query $metaQuery Metadata query container + * @property \WP_Date_Query $dateQuery Date query container + * @property object|array $queriedObject Holds the data for a single object that is queried. + * @property int $queriedObjectId The ID of the queried object. + * @property string $request Get post database query + * @property array $posts List of posts. + * @property int $postCount The amount of posts for the current query. + * @property int $currentPost Index of the current item in the loop. + * @property bool $inTheLoop Whether the loop has started and the caller is in the loop. + * @property WP_Post $post The current post. + * @property array $comments The list of comments for current post. + * @property int $commentCount The amount of comments for the posts. + * @property int $currentComment The index of the comment in the comment loop. + * @property int $comment Current comment ID. + * @property int $foundPosts The amount of found posts for the current query. + * @property int $maxNumPages The amount of pages. + * @property int $maxNumCommentPages The amount of comment pages. * @method static void init Initiates object properties and sets default values. * @method static void parseQueryVars Reparse the query vars. * @method static array fillQueryVars(array $array) Fills in the query variables, which do not exist within the diff --git a/src/Support/Wordpress.php b/src/Support/Wordpress.php index 230edc8..9a5aa8b 100644 --- a/src/Support/Wordpress.php +++ b/src/Support/Wordpress.php @@ -1,7 +1,6 @@ post->ID ?? null; + return query()->post->ID ?? null; } /** @@ -32,7 +31,7 @@ class Wordpress */ public static function singular($types = '') { - return Query::singular($types); + return query()->singular($types); } /** @@ -44,7 +43,7 @@ class Wordpress */ public static function archive($types = null) { - return $types === null || empty($types) ? Query::archive() : Query::postTypeArchive($types); + return $types === null || empty($types) ? query()->archive() : query()->postTypeArchive($types); } /** @@ -66,7 +65,7 @@ class Wordpress } } - return Query::author($users); + return query()->author($users); } /** diff --git a/src/helpers.php b/src/helpers.php index 3aabd44..f51492f 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -1,5 +1,33 @@ ID); + } +} if (!function_exists('meta')) { /** -- libgit2 1.7.2