-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override post-template to support orderby rand #33
- Loading branch information
1 parent
8de77de
commit 0022420
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* Overrides core/post-template | ||
* | ||
* Hack until a solution is delivered in Gutenberg. | ||
* | ||
* @param $attributes | ||
* @param $content | ||
* @param $block | ||
* @return string | ||
*/ | ||
function thisis_render_block_core_post_template( $attributes, $content, $block ) { | ||
$block = thisis_post_template_fiddle( $attributes, $content, $block ); | ||
$html = gutenberg_render_block_core_post_template( $attributes, $content, $block ); | ||
return $html; | ||
} | ||
|
||
/** | ||
* Fiddles the query to support orderby=rand when the className is "rand". | ||
* | ||
*/ | ||
function thisis_post_template_fiddle( $attributes, $content, $block ) { | ||
$className = isset( $attributes['className']) ? $attributes['className'] : null; | ||
if ( $className && 'rand' === $className ) { | ||
$block->context['query']['orderBy'] = $className; | ||
} | ||
//bw_trace2(); | ||
return $block; | ||
} | ||
|