Skip to content

Instantly share code, notes, and snippets.

View hnla's full-sized avatar

Hugo - hnla hnla

  • London
View GitHub Profile
@hnla
hnla / WP-dropdown-style-dropin
Last active December 16, 2015 06:19
A simple set of rulesets to add dropdown styling for WP menu structures.
/*
* A basic dropdown set of styles for WP wp_nav_menu() / wp_pages_list()
* This dropin group of rulesets uses a top level selector nav#site-main which needs to be changed to suit or added to markup.
* There is a simple series of CSS Transitions to provide a little smoothness to the opening / closing of the menu and opacity * transitioned on the li elements.
* There are background colours added and obviously these are subjective and won't suit all themes so need changing
* There is a comlimentary JS snippet that just adds classes to hovered li elements and their parents, this is named in time * honoured manner as 'sfhover' it's real purpose used to be to provide support for IE but are also useful to provide xpath * navigation back up the li nodes and used here to add li backgrounds on all hovered elements parents. In addition the script * Adds a class 'has-child' to li elements having nested ul li children.
*/
/* Configure main menu dropdowns */
nav#site-main ul li {
@hnla
hnla / hnla-loggin-bp-sidebar-me
Last active December 17, 2015 06:09
A function to add the BuddyPress sidebar-me logged in username/avatar, plus site wide notice & a custom rendering of a users notifications displayed as a list e.g new @mentions, new private messages etc. On logout or logged out a login form is presented. The function can be placed in functions.php and the function call added to any sidebar file …
function hnla_bp_login_bp_sidebar_me() {
/**
* This function provides BP sidebar login form if logged out
* welcome message username & logout link if logged in,
* list of any new notification on your account,
* sitewide site notices if any posted by site admin.
*
* Add function to your function.php file
* call function in any sidebar file using:
*
@hnla
hnla / BuddyPress username shortcode
Last active December 17, 2015 14:09
Needed a means of adding a user name to a WP page in a BuddyPress site the other day, easiest approach for this seemed to be a shortcode that the admin could add to the page.
/*
* Add BP username via a shortcode function
* Use in pages or posts?
* For no real reason one can pass a specific user id through
*/
function display_username_in_posts($atts) {
$bp = buddypress();
extract(shortcode_atts(array(
"id" => '',
), $atts));
@hnla
hnla / Shortcode get_post mini-loop
Created May 23, 2013 15:58
Simple mini post loop using on get_post and passing args for category id, qnt, and thumbs excerpts, intended for use in pages primarilly to render a light cat list of title links.
/*
* Shortcode get_post loop
*
* Shortcode displays loops for categories in posts or pages.
* It takes params for cat ID, qnt, show_thumbs, show_excerpt & height / width.
*
* [hnla_cat_loop cat_id='4' qnt='4' show_thumb=true show_excerpt=true, height='120', width='120' ]
*
* If showing thumbnails additional markup elements wrap the title and excerpt to allow positioning to right side of
* floated thumbnail.
@hnla
hnla / BP User Account Links Shortcode
Last active December 18, 2015 02:49
This shortcode allows users to add BP user account links to posts or pages or widgets if widgets enabled for shortcode parsing. You can set the account screen to link to as single top level screen or child 'activity', 'activity/mentions' add text required to display for link, add text to display for the title attr on hover label, also you can se…
@hnla
hnla / hnla BP login form widget
Created August 16, 2013 10:13
An implementation of the classic BuddyPress login form and logged in avatar,logout link provided as a widget.
add_action('widgets_init', create_function('', 'return register_widget("HNLA_loggin_Widget");') );
class HNLA_loggin_Widget extends WP_Widget {
function __construct() {
parent::__construct(
'HNLA_loggin_Widget',
'BP Login, Logout form',
array( 'description' => __('Displays the standard BP login form and logged in avatar, logout link', 'hnla'), )
);
@hnla
hnla / BP Sitewide messages widget
Created August 16, 2013 10:26
Provides an implementation of BuddyPress sitewide message function in a widget for use in site sidebars, can replace BP legacy_theme wp_footer rendering.
add_action('widgets_init', create_function('', 'return register_widget("HNLA_bp_sitewide_messages_Widget");') );
class HNLA_bp_sitewide_messages_Widget extends WP_Widget {
function __construct() {
parent::__construct(
'HNLA_bp_sitewide_messages_Widget', //the ID?
'HNLA BP Sitewide Messages', //the widget name
array( 'description' => __('Displays the BP admin \'all users\' sitewide messages', 'meson'), )
);
// Cache busting dynamically
function get_file_last_mod($filename) {
$filename = dirname(__FILE__) . '/assets/css/' . $filename;
if( file_exists($filename) ){
$version = date ("M d Y H:i:s.", filemtime($filename));
}else{
// manual cache busting
$version = 'V1.0';
}
return $version;