Events

April 21st, 2013

Event Shortcode

/* ------------------- THEME FORCE ---------------------- */
/*
 * EVENTS SHORTCODES (CUSTOM POST TYPE)
 * http://www.noeltock.com/web-design/wordpress/how-to-custom-post-types-for-events-pt-2/
 */
// 1) FULL EVENTS
//***********************************************************************************
function tf_events_full ( $atts ) {

// - define arguments -
extract(shortcode_atts(array(
    'limit' => '10', // # of events to show
	'description' => '150' // # of Chars to show in description
 ), $atts));

// ===== OUTPUT FUNCTION =====
ob_start();

// ===== LOOP: FULL EVENTS SECTION =====
// - hide events that are older than 6am today (because some parties go past your bedtime) -
$today6am = strtotime('today 6:00') + ( get_option( 'gmt_offset' ) * 3600 );

// - query -
global $wpdb;
$querystr = "SELECT *
    FROM $wpdb->posts wposts, $wpdb->postmeta metastart, $wpdb->postmeta metaend
    WHERE (wposts.ID = metastart.post_id AND wposts.ID = metaend.post_id)
    AND (metaend.meta_key = 'tf_events_enddate' AND metaend.meta_value > $today6am )
    AND metastart.meta_key = 'tf_events_enddate'
    AND wposts.post_type = 'tf_events'
    AND wposts.post_status = 'publish'
    ORDER BY metastart.meta_value ASC LIMIT $limit";

$events = $wpdb->get_results($querystr, OBJECT);

// - declare fresh day -
$daycheck = null;
// - loop -
if ($events):
global $post;
foreach ($events as $post):
setup_postdata($post);

// - custom variables -
$custom = get_post_custom(get_the_ID());
$sd = $custom["tf_events_startdate"][0];
$ed = $custom["tf_events_enddate"][0];
?>
<div class="full-events"><!--?php 

// - determine if it's a new day -
$longdate = date("l, F j, Y", $sd);

if ($daycheck == null) { echo '<br ?-->
<h3 class="title">' . $longdate . '</h3>
'; } if ($daycheck != $longdate &amp;&amp; $daycheck != null) { echo '
<h3 class="title">' . $longdate . '</h3>
'; } // - local time format - $time_format = get_option('time_format'); $stime = date($time_format, $sd); $etime = date($time_format, $ed); // - output - ?&gt;
<table>
<tbody>
<tr>
<td class="time"></td>
</tr>
<tr>
<td></td>
</tr>
</tbody>
</table>
</div>
<?php // - fill daycheck with the current day - 
$daycheck = $longdate; 
endforeach; else : endif; 
// ===== RETURN: FULL EVENTS SECTION ===== 
$output = ob_get_contents(); 
ob_end_clean(); 
return $output; 
} 
add_shortcode('events', 'tf_events_full'); 
// You can now call onto this shortcode with [tf-events-full limit='20'] ?>

Structured Umbraco Page Titles

January 22nd, 2013

If you are looking for some code to generate tiered page titles within Umbraco here is an example that worked for our site. This code assumes you are using pageTitle as a DocType element.

Read the rest of this entry »

Creating Custom Fallback Navigation

July 30th, 2012

When creating WordPress themes, sometimes it’s necessary to create your own menus. With 3.0+ you are able to create menus as well as a fallback menu.

Within the fallback_cb, you can actually call your own functions to create a customized menu (helpful when developing for network of blogs).

Here’s what you’ll need to do.

1. Activate Custom Menus

How to Add Custom Navigation Menus in WordPress 3.0 Themes

2. Place your Menu in the Template

Ex:

wp_nav_menu( array( 'theme_location' => 'top-nav', 'depth' => 1, 'menu_name', 'Top Nav', 'menu_class' => 'menu', 'fallback_cb' => 'yourCustomMenuName') );

3. Create a new Function (within functions.php)

function yourCustomMenuName() {
<div class="menu">
<ul>
	<li>Menu Item 1</li>
	<li>Menu Item 2</li>
	<li>Menu Item 3</li>
</ul>
</div>
}

4. Test it!

Add and remove your custom menu (from Appearance => Menu) to see if your custom menu displays as the fallback and you’re done!

Adding @Username to Jetpack Sharedaddy

June 21st, 2012

Edit: Apparently, WordPress is being sticklers. When trying to update the code after a recent update, I tried both methods of adding my username to the tweet button. Only to find out neither work. For whatever reason, they are adamant about not allowing this to happen. Hopefully a solution will be worked out, because the API allows it.

It’s actually rather simple. However, it’s not technically just adding data-via=”USERNAME”. Unfortunately that doesn’t quite work right.

However, you can just add your username to the text inside of the Sharedaddy Module. Please note, I do not take any responsibility for broken code. I’m just giving you the potential for a work around.

You will want to edit this file: jetpack/modules/sharedaddy/sharing-sources.php – In this block of code.

return '
<div class="twitter_button"><iframe style="width: 97px; height: 20px;" src="http://platform.twitter.com/widgets/tweet_button.html?url='&lt;br /&gt;&lt;br /&gt; . rawurlencode( apply_filters( 'sharing_permalink', get_permalink( $post-&gt;ID ), $post-&gt;ID, $this-&gt;id ) )&lt;br /&gt;&lt;br /&gt; . '&amp;counturl='&lt;br /&gt;&lt;br /&gt; . rawurlencode( str_replace( 'https://', 'http://', get_permalink( $post-&gt;ID ) ) )&lt;br /&gt;&lt;br /&gt; . '&amp;count=horizontal&amp;text='&lt;br /&gt;&lt;br /&gt; . rawurlencode( apply_filters( 'sharing_post_title', $post-&gt;post_title, $post-&gt;ID, $this-&gt;id ) )&lt;br /&gt;&lt;br /&gt; . ': " frameborder="0" scrolling="no" width="320" height="240"></iframe></div>
';';

Simply Add your username (however you wish) after . '&count=horizontal&text='

I personally used:

. '&amp;count=horizontal&amp;text=Via @McMullen_Greg: '
. rawurlencode( apply_filters( 'sharing_post_title', $post-&gt;post_title, $post-&gt;ID, $this-&gt;id ) )
. ': " style="width:97px; height:20px;"&gt;

Which displays Via @McMullen_Greg: POST TITLE: URL

Not the greatest, but it does the job!

Edit: After tinkering around a little bit more, I figured out that Sharedaddy uses the Iframe version of the share button. You can easily add your usename by using query string parameters.

So instead of the above code use this.

<div class="twitter_button"><iframe style="width: 97px; height: 20px;" width="320" height="240"></iframe> src="http://platform.twitter.com/widgets/tweet_button.html?via=USERNAME&amp;url='
. rawurlencode( apply_filters( 'sharing_permalink', get_permalink( $post-&gt;ID ), $post-&gt;ID, $this-&gt;id ) )
. '&amp;counturl=' . rawurlencode( str_replace( 'https://', 'http://', get_permalink( $post-&gt;ID ) ) )
. '&amp;count=horizontal&amp;text='
. rawurlencode( apply_filters( 'sharing_post_title', $post-&gt;post_title, $post-&gt;ID, $this-&gt;id ) )
. ': " frameborder="0"
scrolling="no" width="320" height="240"&gt;</div>
&nbsp;

As you can see, we did use VIA=USERNAME instead of just adding to the text. With that, you can also add related, count or other properties as needed! Please ask if you have any questions.

Resources: Tweet Button Documentation | How to add a tweet button in wordpress with iframe code

Facebook Contact Forms with AJAX and PHP

October 7th, 2011

While working today, I was having an issue finding information on how to add a lead capture form on our Facebook Page. Luckily I stumbled across this amazing post! Submitting a Contact Form via AJAX From Your Facebook Page

However, this solution didn’t completely work out of the box so I had to pull some knowledge in from working on previous PHP Forms.

The Facebook Code

Both of these pieces of code should be placed on your Static HTML Page/Tab

The Form

<form action="http://YOURWEBSITE.com/form_submit.php" method="post">
	 <p>
		  <label for="name">Name:</label>
		  <input type="text" name="name" id="name" />
	 </p>
	 <p>
		  <label for="email">Email:</label>
		  <input type="text" name="email" id="email" />
	 </p>
	 <button type="submit" onclick="return submitAjaxForm();">Submit</button>
	 <p id="ajaxMessage"></p>
</form>

The AJAX

<script><!--
function submitAjaxForm()
{
	// declare a new FBJS AJAX object
	var ajax = new Ajax();
	ajax.responseType = Ajax.FBML;
	// define a callback to handle the response from the server
	ajax.ondone = function(data)
	{
		document.getElementById('ajaxMessage').setInnerFBML(data);
	}
	// let the user know we're sending the data
	document.getElementById('ajaxMessage').setInnerXHTML('Submitting your information, please wait...');
	// collect field values
	var queryParams = { 'name' : document.getElementById('name').getValue(), 'email' : document.getElementById('email').getValue() };
	ajax.post('http://mywebsite.com/form_submit.php', queryParams);
	return false;
}
//--></script>

Please note that either of these can be edited to add or remove form fields. You just need to check to make sure the queryParams are updated in the Ajax as they are queried by the “getElementById” function

The PHP

I don’t know any other scripting languages at the moment and don’t have a desire to learn others at this point so everything else was done in PHP. The default PHP script can be found at the link above. This modified script will allow you to send an email using the PHP Mail function.

<?php
// Set Default Timezone to Indianapolis for Submission Date/Time
	date_default_timezone_set('America/Indianapolis'); 
// Get User Content from the Form
	$name = stripslashes($_POST['name']);
	$email = stripslashes($_POST['email']);
	$phone = stripslashes($_POST['phone']);
	$address = stripslashes($_POST['address']);
	$products = stripslashes($_POST['product']);
// Set Date for when Submission was Sent
	$date = date('F d, Y @ h:i a', time());	

// Email headers and subject information
	$headers  = 'MIME-Version: 1.0' . "rn";
	$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn"; //HTML Content Type
	$headers .= 'From: ' . $name . '<' . $email . '>'; //Who's it from? The person that filled out the form!
        $subject = 'YOUR EMAIL SUBJECT';
	$recipient = 'You@YourDomain.com';
	 
	$msg =          "<strong>Submission Info:</strong>" .
			"<br /><br />" .
			"<strong>Submitted: </strong>" . $date . "<br />" .
			"<strong>Name: </strong>" . $name . "<br />" .
			"<strong>Phone: </strong>" . $phone . "<br />" .
			"<strong>Email: </strong>" . $email . "<br />" .
			"<strong>Address: </strong>" . $address . "<br />" .
			"<strong>Product: </strong>" . $products ."<br />" .
			"<strong>How they Found Us: </strong>Facebook";

 	//Mail $msg to the recipient on the form
      if (mail($recipient, $subject, $msg, $headers))
		 {
		 	//Output a confirmation that the email has been sent
	 		echo "<p><strong>" . $name . " Your Entry has been submitted. </strong><p>"; 
		}
     else //Error Message if problems arise
	 {
     	    echo "<p>Message failed to send.";
	 }
?>

This is the code that I used. I plan on updating to counter an empty form. But haven’t had the time to do that as of yet. Let me know if you have any thoughts on how to improve a lead capture form on a Facebook page! Please note that I did NOT write this code and all credit should go to the original author George Huger and his post Submitting a Contact Form via AJAX From Your Facebook Page