Skip to content

Instantly share code, notes, and snippets.

View michaelbrazell's full-sized avatar

Mike Murray michaelbrazell

View GitHub Profile
/**
* A dashboard widget that lists out pages in a heirarchy
* Add this to the end of your "Functions.php" file in your theme directory
*
* This function is hooked into the 'wp_dashboard_setup' action below.
*/
function site_map_edit() {
wp_add_dashboard_widget(
'site_map_edit', // Widget slug.
@michaelbrazell
michaelbrazell / wordpress_conditional.php
Created July 16, 2014 01:58
Using a conditional for a custom field in a Wordpress theme
<?php
// Assign the custom field to a variable
$her_final_word = get_post_meta($post->ID, 'her_final_word', true);
// Check if variable is not empty
if($her_final_word !='') {
// True: Print the variable
?><p><?php echo $her_final_word; ?></p><?php
}
else {
// Default text that will appear
<?php
/**
* The template used for displaying page content in page.php
*
* @package doc
*/
?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
@michaelbrazell
michaelbrazell / gist:836f529ea4000c2b9cff
Created September 22, 2014 15:57
Looping through a post outside of Wordpress
<!-- This is called in the head of this file -->
<?php require('./blog/wp-blog-header.php'); ?>
<!-- way down the page -->
<div class="feature_blog">
<div class="feature_blog_content">
<h4>The Distance Lens Blog</h4>
<?php
$args = array( 'numberposts' => '1', 'category' => '1');
<?php
/**
* I am creating a function here because I am calling it in my template
* using custom_header_template();
* but you do not need to do this
* Additionally, I have a lot of fields that I need to pull in, so I am assigning each one as a variable
* One of those fields is an image and I need the URL so I use the pods_image_url filter
* Additionally, I have a WYSYWIG that has custom shortcodes in it, so I have to use do_shortcode(); to call that field for the shortcode to be executed
*/
@michaelbrazell
michaelbrazell / Pods_Loop-through-post-type-by-category
Last active August 29, 2015 14:11
Usings Pods to loop through a number of posts outside the loop (in this case a custom pod called "links" ) and displaying them by category
<?php
// Declare paremeters of Pods
// Limiting by 4, and looping through the category slug called "for-parents"
$params = array(
'limit' => 4,
'where' => "category.slug = 'for-parents'"
);
// Create a variable called $links and assign that my pod called "link" pulling in the parameters from above
$links = pods('link', $params );
// If there are more than 0 links, let's display them!
@michaelbrazell
michaelbrazell / WP Loop Through Custom Post Type with JSON
Last active September 24, 2018 06:21
Using WP REST API to Loop through Custom Post type with JSON
<html>
<head>
<title>Looping through json object</title>
<script type="text/javascript">
/*
Looping through your custom post type data using Wordpress rest API
You'll need this plugin as of 1/15/2015. http://wp-api.org/
Eventually this will be included in the WP Core. Supposed to be with 4.1, but that didn't happen.
*/
</script>
@michaelbrazell
michaelbrazell / Author-Capabilities.php
Last active August 29, 2015 14:15
WP Add author capabilities to moderate comments to
<?php
/* Use this in Functions.php */
function add_publish_caps() {
// gets the contributor role
$role = get_role( 'contributor' );
// Adds capability to moderate comments, edit posts, but not publish posts.
// moderate_comments requires edit_posts which is why we need the remove_cap.
$role->add_cap( 'edit_posts' );
@michaelbrazell
michaelbrazell / XBL-Screenshot-Data
Created April 14, 2015 15:28
One time pull of my screenshot data from Xbox Live using Xbox Live API
[{"screenshotId":"95ee50ce-d030-49ff-9f4c-acb9d80cc80e","resolutionHeight":1080,"resolutionWidth":1920,"state":"Published","dateTaken":"2015-04-12 20:55:20","lastModified":"2015-04-12 20:55:36","userCaption":"","type":"UserGenerated","scid":"28360100-1f6f-4a8d-b425-4dbd7ffe16e1","titleId":2147358433,"rating":0,"ratingCount":0,"views":0,"titleData":"","systemProperties":"878353f4-d619-44d9-8d9d-161e81c17a83;","savedByUser":false,"achievementId":"","greatestMomentId":"","thumbnails":[{"uri":"http:\/\/screenshotscontent-t5001.xboxlive.com\/00090000004fa942-95ee50ce-d030-49ff-9f4c-acb9d80cc80e\/Thumbnail_Small.PNG","fileSize":80252,"thumbnailType":"Small"},{"uri":"http:\/\/screenshotscontent-t5001.xboxlive.com\/00090000004fa942-95ee50ce-d030-49ff-9f4c-acb9d80cc80e\/Thumbnail_Large.PNG","fileSize":258104,"thumbnailType":"Large"}],"screenshotUris":[{"uri":"http:\/\/screenshotscontent-t5001.xboxlive.com\/00090000004fa942-95ee50ce-d030-49ff-9f4c-acb9d80cc80e\/Screenshot-Original.png?sv=2013-08-15&sr=c&sig=Av3Oz549hie
@michaelbrazell
michaelbrazell / XBL-ScreenShots-from-JSON
Last active August 29, 2015 14:19
Pull Screenshots from JSON datasource with a download link
<html>
<head>
<title>Screenshots!</title>
</head>
<body>
<h1>Screenshots!</h1>
<div id="container">
</div>
</body>