How to make wordpress APPs

Just create CPT and Taxonomies and paste this code into you archive.php, it will display different dropdowns with each taxonomy you have.

<?php
if (is_post_type_archive() || is_tax()) :
$post_type_obj = get_queried_object();
 
 //if is tax, we'll have to append taxonomies cause they doesnt exist on "taxonomy object".
 if(is_tax()){
 
 $taxs = get_taxonomy($post_type_obj->taxonomy);
 $taxs = $taxs->object_type;
 $taxs = get_taxonomies(array('object_type'=>$taxs),'names');
 $post_type_obj->taxonomies = $taxs;
 }
 
 if(empty($post_type_obj->taxonomies)){
 return;
 }
 
 echo '<form id="recipesFilters" method="get" action="">';
 echo '<label>FILTER BY</label>';
 
 foreach ( $post_type_obj->taxonomies as $tax_name ) {
 
 $tax = get_taxonomy($tax_name);
echo '<select name="'.$tax->query_var.'">';
 
 $type = get_terms( array($tax->query_var), array('hide_empty'=>true) ); 
 
 echo '<option value="">'.$tax->labels->name.'</option>';
 
 foreach ($type as $t){
 echo '<option value="'.$t->slug.'">'.$t->name.'</option>';
 }
 
 echo '</select>';
 
 }
 
 echo '<input type="submit" value="Search" />';
 echo '</form>';
 
endif;
?>

Slide Pages with Ajax

I will write an awesome tutorial about this but in the meantime you can download the zip and see how it works, in the future i would like to make a free wordpress theme with this system, the only problem would be the handling of urls loaded throught ajax, if you have experience in that field, please contact me!

Continue reading

Change default WordPress header in mail

There is a bug in in contact form 7 plugin, it happens when you use PIPES ( | ) to change the recipient address, so doing this you can fix it, if you dont understand me, take a look at : contactform7.com/selectable-recipient-with-pipes

The code is pretty simple, you just have to know what a wordpress filter is!

function site_mail_from_name ($mail_from_name) {
  $site_mail_from_name = 'YOUR_WEB_SITE_NAME';
  if(empty($site_mail_from_name)) {
    return $mail_from_name;
  }
  else {
    return $site_mail_from_name;
  }
}

add_filter('wp_mail_from_name','site_mail_from_name',1);

Obviously change “YOUR_WEB_SITE_NAME” by your website name…., and this should be inside your functions.php!

Go back to parent Term

You can read the commented lines to understand the code, it’s quite simple!
Paste this in your taxonomy.php!

 <?php
    //get the global term SLUG from $wp_query variable..
    $term_slug = get_query_var('term'); 

    // get all info related to that term
    $term_info = get_term_by( 'slug',$term_slug ,'YOUR_TAXONOMY'); 

    // this line converts to integer the id of the parent cat!
    $parent = (int)$term_info->parent; 

    //Use get_term_link() function to print the correct link to the parent taxonomy, 
    //we also CHECK if there is any parent, otherwise, do nothing..
    echo ($parent)?'<a href="'.get_term_link( $parent , 'YOUR_TAXONOMY').'">Go Back</a>':''; 

?>

Get url paramentes in Actionscript3 from swf

I always use flashvar params, but i find out there is another way to do it!

var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
trace(paramObj["youparamname"]);

All you have to do is add parameters into the movie url!

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0"
id="flash_x01" width="500" height="500">

<param name="movie" value="vars.swf?youparamname=xxxx;
<param name="menu" value="false">
<param name="quality" value="high">

<embed src="vars.swf?youparamname=xxxx" width="500" height="500" menu="false" quality="high"
swliveconnect="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</embed>
</object>

List posts in categories from wp_list_categories()

//USAGE:
//wp_list_categories( array( 'title_li' => '', 'echo' => false , 'walker' => new PCWalker() ) ) .

class PCWalker extends Walker_Category {

function end_el(&$output, $page, $depth, $args) {
global $wpdb;
$output .= "called with: " . $page->term_id;
$posts = $wpdb->get_results("select object_id as ID from wp_term_relationships r "
. "join wp_posts p on r.object_id = p.ID where p.post_status = 'publish' and r.term_taxonomy_id = "
. "(SELECT term_taxonomy_id FROM wp_term_taxonomy WHERE taxonomy = 'category' and term_id = " . $page->term_id . ")");
if($posts) :
$output .= '<ul>'; foreach($posts as $post) { $output .= '
<li>'; $output .= '<a title="link to ' . get_the_title($post->ID) . '" href="' . get_permalink($post->ID) . '">' . get_the_title($post->ID) . '</a>'; $output .= '</li>
'; } $output .= '</ul>
';
endif;
parent::end_el(&$output, $page, $depth, $args);
}
}

Source: www.cselian.com

Youtube link on WordPress CustomField

So your client just have to copy and paste the url into the custom field named “video” And this code will diplay the iframe.

<?php
$meta_value = get_post_meta($post->ID, 'video', true);
if($meta_value){
$url = parse_url($meta_value);
$id = 0;
if($url['host'] == 'youtu.be'){$id = ltrim($url['path'],'/');}
else if(strpos($url['path'],'embed') == 1){$id = end(explode('/',$url['path']));}
else{parse_str($url['query']);$id = $v;}
echo '<p><iframe width="230" height="150" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/'.$id.
'?version=3&amp;wmode=transparent&amp;rel=0&amp;modestbranding=1&amp;loop=0&amp;controls=0&amp;autoplay=0&amp;showsearch=0&amp;iv_load_policy=o">
</iframe></p>';
}
?>

Search by author in WordPress

<?php

if(!is_search()){

get_template_part( 'loop', 'index' );

}else{

echo '<div><h1>Resultados de B&uacute;squeda:</h1></div>';

if(isset($_GET['author'])){

$postsAuthor ='';

$searchAuthor = $_GET['author'];

$postsAuthor = $wpdb->get_col( $wpdb->prepare( "SELECT id FROM $wpdb->users    WHERE display_name LIKE %s", '%'.like_escape($searchAuthor).'%' ) );

if($postsAuthor){
query_posts(array( 'author'=>implode (',',$postsAuthor),'post_type' => array( 'fotos', 'videos'), 'paged' => get_query_var('paged') ) );

get_template_part( 'loop', 'search' );

if(function_exists('wp_pagenavi')) wp_pagenavi();

wp_reset_query();

echo '<div></div>';

}else{
echo 'No se encontraron fotos ni videos de este autor: '.$searchAuthor;
}

}else{

get_template_part( 'loop', 'search' );
if(function_exists('wp_pagenavi')) wp_pagenavi();
echo '<div></div>';

}

}

?>

Jquery Plugins i love (monthly updates)

Fancy Moves

http://webdesignandsuch.com/fancymoves-jquery-product-slider-2/

jQuery Supersized

Comes bundle with 2 versions: http://buildinternet.com/project/supersized/

Javascript Games

Check out some demos: http://craftyjs.com

Javascript googlemaps

http://leaflet.cloudmade.com/index.html

Caroufredsel

Cuztomizable Jquery carousel, you should always use it, lots of options and RESPONSIVE!… Try it here.

Pajination

Really Flexible, easy to use and lots of customization options, go ahead and take a look:

http://th3silverlining.com/2010/04/15/pajination-a-jquery-pagination-plugin/

NivoSlider

Definitely NIVO SLIDER is one of the best choices of jquery slider, and of course my favorite!, i want to encourage you to try it, it’s really flexible, easy to customize code and css styles, and it is available for WORDPRESS too!.. Amazing!

Jquery Flip!

A heavy but beatifull solution to make flip content.. Visit Here. If you would like something ligther you may want to use QuickFlip 2.

 

One thing you should never forget about jquery

Never ever forget how to ask if an object exist:

if($('#object').length){ ... }
//or
if($('#object').length > 0){ ... }
//or
if($('#object')[0]){ ... }

Use your prefer, and remember: jquery will always return an object( $(‘xxx’) ), even if it doesnt exist, so if you want to know if an object exist you must to do it correctly.

Fix ie 8 select

If you are reading at this post, it’s because you already know the problem,…. so the javascript (jquery) solution to avoid options has the same widht as the select is:

jQuery(document).ready(function($) {

    $("xXxxXxXx select").hover(
        function(){
        $(this)
        .data("origWidth", $(this).css("width"))
        .css("width", "auto");        
        },function(){
        $(this).css("width", $(this).data("origWidth"));
    });

});

Jquery 1.7 slideToogle, slideUp, slideDown issue in IE8

Well after reading like 10 different websites, it seems like the problem was because of negative padding and margins, but i did not used negative values at all… so the WTF!!, anyway, you can grab the solution right here:

Chage:

_default:function(a){a.elem.style&&a.elem.style[a.prop]

by:

_default:function(a){if(isNaN(a.now)){return;}a.elem.style&&a.elem.style[a.prop]

Javascript Split() html crossbrower.

I know it sounds a little bit crazy, but it is true, if you do something like this:

InfoArray = $('#myInfo').html().split('<h2>---</h2>');

It will not work in IE 6,7,8. So the first question in your mind: ¿¿WTF??, internet explorer 6,7,8 will see html tags in capital letters: .split(‘<H2>—</H2>’).

So if you want to fix it, you can do something like this using jquery:

if ( $.browser.msie==true && $.browser.version <9)
InfoArray = $('#myInfo').html().split('<H2>---</H2>');
else
InfoArray= $('#myInfo').html().split('<h2>---</h2>');

If you have a better solution, please let me know it!

WordPress simple tips, advance functionability.

I will UPDATE this post every time i discover a new one!

  1. Count system for post in wordpress

    This will create automatically a new Custom Field for your post count, called “count_page_hits”. If you want to know how to display them visit: http://codex.wordpress.org/Custom_Fields

    function count_page_hits() {
     if(is_single()) {
       global $post;
       $count = get_post_meta($post->ID, 'count_page_hits', true);
       $newcount = $count + 1;
    
       update_post_meta($post->ID, 'count_page_hits', $newcount);
     }
    }
    add_action('wp_head', 'count_page_hits');

    Source: Bavotasan.com