Add helper methods
Diff
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(-)
@@ -19,8 +19,8 @@ class WordpressTemplatingServiceProvider extends ServiceProvider
public function boot()
{
Blade::directive('loop', function () {
return '<?php if (Koselig\Facades\Query::hasPosts()): while (Koselig\Facades\Query::hasPosts()): '
. 'Koselig\Facades\Query::post(); $loop = app(\'loop\'); ?>';
return '<?php if (query()->hasPosts()): while (query()->hasPosts()): '
. 'query()->post(); $post = post(); ?>';
});
Blade::directive('endloop', function () {
@@ -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
@@ -1,7 +1,6 @@
<?php
namespace Koselig\Support;
use Koselig\Facades\Query;
use Koselig\Models\User;
/**
@@ -20,7 +19,7 @@ class Wordpress
public static function id()
{
// can't use facades to access properties unfortunately!
return app('query')->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);
}
/**
@@ -1,5 +1,33 @@
<?php
use Koselig\Models\Meta;
use Koselig\Models\Post;
if (!function_exists('query')) {
/**
* Get the main query or convert a query to a {@link \Koselig\Proxy\Query} proxy instance.
*
* @param WP_Query|null $query
* @return \Koselig\Proxy\Query
*/
function query(\WP_Query $query = null)
{
return ($query === null) ? app('query') : Query::instance($query);
}
}
if (!function_exists('post')) {
/**
* Get the current post in The Loop, or convert a {@link \WP_Post} instance to a Koselig
* post.
*
* @param WP_Post|null $post
* @return Post|null
*/
function post(WP_Post $post = null)
{
return ($post === null) ? app('loop') : Post::find($post->ID);
}
}
if (!function_exists('meta')) {
/**