Categories
PHP programming

WordPress plugin: insert link to latest post (in category) on your menu

Instructions:

  1. Copy/paste this into your functions.php (TODO: convert it to a standalone php file, and make it into a plygin you can activte/deactivate)
  2. Create a new menu item of type “custom URL”
  3. Make your URL “http://#latestpost:category_name”
    • where “category_name” is the name of the category whose latest post you want to link to
  4. Make the name whatver you want to appear on the menu
  5. Profit!

Based on an idea (with some upgrading + bugfixes for latest WordPress in 2016) from http://www.viper007bond.com/2011/09/20/code-snippet-add-a-link-to-latest-post-to-wordpress-nav-menu/

[php]
/** Adam: add support for putting ‘latest post in category X’ to menu: */
// Front end only, don’t hack on the settings page
if ( ! is_admin() ) {
// Hook in early to modify the menu
// This is before the CSS "selected" classes are calculated
add_filter( ‘wp_get_nav_menu_items’, ‘replace_placeholder_nav_menu_item_with_latest_post’, 10, 3 );
}

// Replaces a custom URL placeholder with the URL to the latest post
function replace_placeholder_nav_menu_item_with_latest_post( $items, $menu, $args ) {

$key = ‘http://#latestpost:’;

// Loop through the menu items looking for placeholder(s)
foreach ( $items as $item ) {

// Is this the placeholder we’re looking for?
if ( 0 === strpos( $item->url, $key ) )
{

$catname = substr( $item->url, strlen($key) );
// Get the latest post
$latestpost = get_posts( array(
‘posts_per_page’ => 1,
‘category_name’ => $catname
) );

if ( empty( $latestpost ) )
continue;

// Replace the placeholder with the real URL
$item->url = get_permalink( $latestpost[0]->ID );
}
}

// Return the modified (or maybe unmodified) menu items array
return $items;
}
[/php]

Categories
games design

Better than Civ6? Bookmarkable links for Civ4 mod: Master Of Mana sources

Master of Mana was a great game – much better than Civ5, and from what we’ve seen of Civ6, Firaxis is still playing catch-up in a few areas :).

The author has disappeared, and his website has been taken over by scammers (not even going to link it), but the community has kept going the SourceForge-hosted copy of the source and continues to update it. The files are ordered confusingly (inherited from previous projects, and Civ4 itself, which was mainly shipped as a commercial game, not as a moddable game!). Here’s a few key links to find interesting / useful game-design gems: