Skip to content

Instantly share code, notes, and snippets.

@mgmartel
Last active December 10, 2015 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mgmartel/4454318 to your computer and use it in GitHub Desktop.
Save mgmartel/4454318 to your computer and use it in GitHub Desktop.
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