How To Show Top Level And Child Pages In WordPress
The following snippet will let you show top level and child pages in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<ul><?php $parent_title = get_the_title($post->post_parent);?> <li><a href="<?php echo get_permalink($post->post_parent) ?>"><?php echo $parent_title;?></a></li></ul> <?php if ($post->post_parent) { $ancestors=get_post_ancestors($post->ID); $root=count($ancestors)-1; $parent = $ancestors[$root]; } else { $parent = $post->ID; } $children = wp_list_pages("title_li=&child_of=". $parent ."&echo=0"); if ($children) { ?> <ul id="subnav"> <?php echo $children; ?> </ul> <?php } ?> |
How To Have A/B Split Google Optimizer For WordPress
The following snippet will like you to have A/B split Google optimizer testing done for WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
//Custom Headers for A/B Split Landing Pages function insert_splittest_header() { if (is_page(8582)) { ?> <!-- Google Website Optimizer Control Script --> <script> function utmx_section(){}function utmx(){} (function(){var k='0785944995',d=document,l=d.location,c=d.cookie;function f(n){ if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return escape(c.substring(i+n. length+1,j<0?c.length:j))}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash; d.write('<sc'+'ript src="'+ 'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com' +'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime=' +new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+ '" type="text/javascript" charset="utf-8"></sc'+'ript>')})(); </script><script>utmx("url",'A/B');</script> <!-- End of Google Website Optimizer Control Script --> <!-- Google Website Optimizer Tracking Script --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['gwo._setAccount', 'UA-23025259-1']); _gaq.push(['gwo._trackPageview', '/0785944995/test']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <!-- End of Google Website Optimizer Tracking Script --> <?php } } add_action('wp_head','insert_splittest_header',0); // Customer Footer for final page - the 'thank you' function insert_B_footer () { if (is_page(9161)) { ?> <!-- Google Website Optimizer Tracking Script --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['gwo._setAccount', 'UA-23025259-1']); _gaq.push(['gwo._trackPageview', '/0785944995/test']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> <!-- End of Google Website Optimizer Tracking Script --> <?php } } add_action('wp_footer','insert_B_footer'); |
Snippet Source/Credit: Snipplr
How To Have Content From Separate Pages Without ID In WordPress
The following lines of codes will let you have content from separate pages without ID in WordPress.
1 2 3 4 5 6 7 8 9 10 11 |
<?php //PERFORMS MYSQL QUERY TO GET THE POST ID //note: 'about' is the name of the page, you can use any named, ex: 'web services' $about_page_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = 'about'"); $post_id = get_post($about_id); $content = $post_id->post_content; //applies wordpress filter (includes <p> tags) $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); echo $content; ?> |
How To Add Gravatars For Authors In WordPress
Simply paste the following snippet and you will be able to automatically add the author gravatar to each of their posts respectively.
1 |
<?php echo get_avatar( get_the_author_email(), '80' ); ?> |
Snippet Source/Credit: emoticode
How To Add PayPal Functionality In WordPress
Using the following snippet will let you add PayPal button to your WordPress website. Remember to add the snippet to your theme’s functions.php file and you are done.
1 2 3 4 5 6 7 8 9 10 11 |
function cwc_donate_shortcode( $atts ) { extract(shortcode_atts(array( 'text' => 'Make a donation', 'account' => 'REPLACE ME', 'for' => '', ), $atts)); global $post; if (!$for) $for = str_replace(" ","+",$post->post_title); return '<a class="donateLink" href="https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business='.$account.'&item_name=Donation+for+'.$for.'">'.$text.'</a>'; } add_shortcode('donate', 'cwc_donate_shortcode'); |
Snippet Source/Credit: Snipplr