Create a gist now
Instantly share code, notes, and snippets.
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable URL for this gist.
Clone via
HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Use WP Tiles as a site menu, by automatically adding pages on fixed locations in your website. Drop in your functions.php or functions plugin. It only shows pages with the meta value 'tile-position', which is their fixed position in the tiles.
<?php | |
add_filter( 'wp-tiles-data', 'fixed_page_tiles', 10, 4 ); | |
function fixed_page_tiles( $data, $posts, $colors, $tiles_obj ) { | |
$pages = get_pages(); | |
foreach ( $pages as $page ) { | |
$position = get_post_meta( $page->ID, 'tile-position', true ); | |
if ( empty ( $position ) || ! is_numeric ( $position ) ) | |
continue; | |
$tiledata = array ( | |
"id" => $page->ID, | |
"title" => $page->post_title, | |
"url" => get_permalink( $page->ID ), | |
"category" => wp_get_post_categories( $page->ID, array ( "fields" => "names" ) ), | |
//"img" => $tiles_obj->get_first_image ( $page ), | |
"img" => get_stylesheet_directory_uri() . '/images/' . $page->post_name . '.png', | |
"color" => $colors[ array_rand( $colors ) ], | |
"hideByline" => true | |
); | |
array_splice ( $data, $position - 1, 0, array ( $tiledata ) ); | |
} | |
return $data; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment