Skip to content

Instantly share code, notes, and snippets.

@levymetal
levymetal / direct_parent.php
Last active November 27, 2023 04:17
Custom Wordpress function which uses a nav walker to display a list of child pages from a common parent, which can be called from either the parent page (displays children) or any of the child pages (displays siblings). Detailed instructions available on my blog post here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-…
<?php
wp_nav_menu( array(
'menu' => 'Menu Name',
'sub_menu' => true,
'direct_parent' => true
) );
<?php
// add hook
add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$root_id = 0;
@levymetal
levymetal / api-service.ts
Last active November 1, 2022 02:48
Example of using observable from within a Service on Ionic 2. Full blog post here: http://christianvarga.com/how-to-create-and-monitor-observables-in-ionic-2-service/
import { Injectable } from '@angular/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import { Observable } from 'rxjs/Observable';
import 'rxjs/Rx';
@Injectable()
export class ApiService {
private errorObserver: any;
public error: any;
@levymetal
levymetal / app.component-partial.ts
Last active November 1, 2022 02:47
How to show the keyboard accessory bar in Ionic 2.0.0-rc.1. Full blog post here: http://christianvarga.com/how-to-show-the-ios-keyboard-accessory-bar-in-ionic-2-0-0-rc-1/
import { StatusBar, Splashscreen, Keyboard } from 'ionic-native';
$('.flickity-slider').flickity({
draggable: Modernizr.touchevents
});
<?php
// add hook
add_filter( 'wp_nav_menu_objects', 'my_wp_nav_menu_objects_sub_menu', 10, 2 );
// filter_hook function to react on sub_menu flag
function my_wp_nav_menu_objects_sub_menu( $sorted_menu_items, $args ) {
if ( isset( $args->sub_menu ) ) {
$current_id = 0;
$root_id = 0;
@levymetal
levymetal / twitter-cache.php
Last active November 1, 2022 02:44
Custom version of my twitter cache that works with multiple usernames. Original here: http://christianvarga.com/how-to-get-public-feeds-using-twitters-v1-1-api/#comment-2121870201
<?php
// call this script using a GET parameter, eg: http://your-domain.com/twitter-cache.php?screen_name=your_twitter_username
error_reporting( 0 ); // don't let any php errors ruin the feed
$username = $_GET['screen_name'];
$number_tweets = 4;
$feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name={$username}&count={$number_tweets}&include_rts=1";
$cache_file = dirname(__FILE__).'/cache/'.'twitter-cache-'.$username;
@levymetal
levymetal / functions.php
Last active November 1, 2022 02:43
Custom adaptation for my sub-menu script that allows you to force a specific sub-menu to be displayed. Full documentation here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-based-on-parent-or-sibling/
<?php
/* usage
*
* wp_nav_menu( array(
* 'theme_location' => 'primary',
* 'sub_menu' => true,
* 'root_id' => id_of_menu_item
* ) );
*/
@levymetal
levymetal / functions.php
Last active November 1, 2022 02:43
Custom adaptation for my sub-menu script that treats first-level items as root-level items. Full documentation here: http://christianvarga.com/how-to-get-submenu-items-from-a-wordpress-menu-based-on-parent-or-sibling/
<?php
/** wp_nav_menu( array(
'theme_location' => 'primary',
'sub_menu' => true
) );
or
wp_nav_menu( array(
<?php
function my_wp_nav_menu( $theme_location = 'primary', $container = false, $items_wrap = "<div class='widget'><nav><ul>%3\$s</ul></nav></div>" ) {
$menu = wp_nav_menu(array(
'container' => $container,
'items_wrap' => $items_wrap,
'sub_menu' => true,
'theme_location' => $theme_location,
'echo' => false
));