Edit

Nodes

Items

112

Per Page

/ 6

Subject Attribute

  • Various WP snippets

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics

    Show Links Menu w/Active Class

    <nav>
    <?php $args=array(
    	'sort_order' => 'ASC',
    	'sort_column' => 'post_date',
    	'hierarchical' => 1,
    	'exclude' => '',
    	'include' => '',
    	'meta_key' => '',
    	'meta_value' => '',
    	'authors' => '',
    	'child_of' => 0,
    	'parent' => -1,
    	'exclude_tree' => '',
    	'number' => '',
    	'offset' => 0,
    	'post_type' => 'page',
    	'post_status' => 'publish'
    );
    $pages = get_pages($args);
    $current_id = get_the_ID();
    if( $pages ){
        echo( "<ul>\n" );
        foreach( $pages as $page){
            $link_page_id = ($page->ID);
            if( $current_id==$link_page_id ) echo( "<li class=\"active\">" );
            else echo( "<li>" );
            echo( "<a href=\"".get_page_link($page->ID)."\">".$page->post_title."</a>" );
            echo( "</li>\n" );
        }
        echo( "</ul>\n\n" );
    }
    ?>
    </nav>

    Show Categories List

    <?php
        echo( "<div id=\"topics\">\n" );
        echo( "<h3>Topics</h3>\n" );
        echo( "<ul>\n" );
        $categories_obj = get_categories( array('orderby'=>'id','hide_empty'=>'1') );
        foreach( $categories_obj as $cat ){
            echo( "<li>" );
            echo( "<a href=\"/category/".$cat->slug."\">".$cat->name."</a>" );
            $posts_in_cat = new WP_Query( 'cat='.$cat->term_id );
            if ( $posts_in_cat->have_posts() ){
                echo( "<ul>\n" );
                while ( $posts_in_cat->have_posts() ){
                    $posts_in_cat->the_post();
                    echo( "<li><a href=\"");
                    the_permalink();
                    echo( "\">" );
                    the_title();
                    echo( "</a></li>\n" );
                }
                echo( "</ul>\n" );
            }
            echo( "</li>\n" );
        }
        echo( "</ul>\n" );
        echo( "</div>\n\n" );
    ?>

    Show Recent Posts List

    <?php
        echo( "<h2>What's New</h2>\n" );
        echo( "<ul>\n" );
        $latest_blog_posts = new WP_Query( array('posts_per_page'=>5) );
        if ( $latest_blog_posts->have_posts() ) :
            while ( $latest_blog_posts->have_posts() ) :
                $latest_blog_posts->the_post();
                // Loop output goes here
                echo( "<li><a href=\"");
                the_permalink();
                echo( "\">" );
                the_title();
                echo( "</a></li>\n" );
            endwhile;
        endif;
        echo( "</ul>\n" );
    }
    ?>

    Show Recent Posts Content

    <?php
        echo( "<?h2>Recent Posts<?/h2>\n" );
        $latest_blog_posts = new WP_Query( array( 'posts_per_page'=>5 ) );
        if ( $latest_blog_posts->have_posts() ){
            while ( $latest_blog_posts->have_posts() ){
                $latest_blog_posts->the_post();
                // Loop output goes here
                echo( "<?div class=\"entry\">\n" );
                echo( "<?h3>" );
                echo( "<?a href=\"" );
                the_permalink();
                echo( "\">" );
                the_title();
                echo( "<?/a>" );
                echo( "<?/h3>\n" );
                echo( "<?div class=\"time\">\n" );
                the_date();
                echo( "@" );
                the_time();
                echo( "<?/div>\n" );
                echo( "<?h4>in Categories<?/h4>" );
                the_category();
                the_content();
                echo( "<?/div>\n\n" );
            }
        }
    ?>

    Show Date Menu

    <?php
        echo("<h2>Archive</h2>\n");
        echo("<ul>\n");
        wp_get_archives();
        echo("</ul>\n");
    ?>

    Show Tag List

    <?php
        echo("<div id=\"tag-bar\">\n");
        echo("<ul>\n");
        $tags_obj = get_tags(array('orderby'=>'name','order'=>'ASC','hide_empty'=>'1'));
        foreach($tags_obj as $tag){
            echo("<li>");
            echo("<a href=\"/tag/".$tag->slug."\">".$tag->name."</a>");
            echo(" (".$tag->count.")");
            echo("</li>\n");
        }
        echo("</ul>\n");
        echo("</div>\n\n");
    ?>

    Add ability to execute php in text widgets

    <?php
    add_filter('widget_text','php_text',99);
    function php_text($text){
        if(strpos($text,'<'.'?')!==false){
            ob_start();
            eval('?'.'>'.$text);
            $text=ob_get_contents();
            ob_end_clean();
        }
        return $text;
    }
    ?>

    Removes the automatic addition of P and BR elements to content

    <?php
    remove_filter('the_content','wpautop');
    remove_filter('the_excerpt','wpautop');
    remove_filter('term_description','wpautop');
    ?>

    Using email as username in account registration

    <?php
    if(isset($_POST['user_login'])&&isset($_POST['user_email'])){
        $_POST['user_login']=$_POST['user_email'];
    }
    ?>

    Storing user-selected password into database on registration

    <?php
    add_action('user_register','ts_register_extra_fields',100);
    function ts_register_extra_fields($user_id){
        $userdata=array();
        $userdata['ID']=$user_id;
        if($_POST['user_password']!==''){
            $userdata['user_pass']=$_POST['user_password'];
        }
        $new_user_id=wp_update_user($userdata);
    }
    ?>

    Add ability to add featured images to pages and posts

    <?php
    add_theme_support('post-thumbnails');
    ?>

    Add ability to execute shortcodes in text widgets

    <?php
    add_filter('widget_text','do_shortcode');
    ?>

    Define menus

    <?php
    if(function_exists('register_nav_menus')){
        register_nav_menus(
            array(
                'main_menu'=>'Main Menu',
                'footer_menu'=>'Footer Menu',
            )
        );
    }
    ?>

    Define widget regions

    <?php
    if(function_exists('register_sidebar')){
        register_sidebar(array(
            'name'=>'Footer',
            'id'=>'footer',
            'before_widget'=>'<div>',
            'after_widget'=>'</div>',
            'before_title'=>'<h2>',
            'after_title'=>'</h2>',
        ));
        register_sidebar(array(
            'name'=>'Footer Right',
            'id'=>'footer_right',
            'before_widget'=>'<div>',
            'after_widget'=>'</div>',
            'before_title'=>'<h2>',
            'after_title'=>'</h2>',
        ));
        register_sidebar(array(
            'name'=>'Sidebar Right',
            'id'=>'sidebar_right',
            'before_widget'=>'<div>',
            'after_widget'=>'</div>',
            'before_title'=>'<h2>',
            'after_title'=>'</h2>',
        ));
    }
    ?>
  • Output a menu

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    <?php
    
    
    $page_menu_items = menu_tree_output(menu_tree_all_data("main-menu"));
    
    echo( drupal_render($page_menu_items) );
    
    
    ?>
  • LDAP Connect and Bind Test

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    <?php
    
    
    $host = "127.0.0.1:10389";
    $ldap = ldap_connect($host);
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    
    
    $username = "uid=admin,ou=system";
    $password = "secret";
    
    
    if( $bind = ldap_bind($ldap, $username, $password) )
    
        echo( "logged into ".$host." as ".$username );
    
    else
    
        echo( "Fail" );
    
    
    ?>
  • Create custom content type

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics

    contenttypetest.info

    name = Contenttype test
    description = Test - how can I create a new content type with hook form?
    core = 7.x
    files[] = contenttypetest.module;
    files[] = contenttypetest.install;

    contenttypetest.module

    <?php
    
        // hook_form implementation
        function contenttypetest_form($node, &$form_state) {
            $form = array();
    
    
            $form['contenttypetest_pass'] = array(
                '#type' => 'password',
                '#title' => t('Type a password'),
                '#description' => t('You can type anything you like.'),
            );
            $form['contenttypetest_veld'] = array(
                '#type' => 'file',
                '#description' => 'You might wanna upload a file!',
                '#title' => 'Bestand',
            );
            return $form;
        }
    
    
        // hook_node_info() implementation
        function contenttypetest_node_info() {
            return array(
                'contenttypetest' => array(
                    'name' => t('Content type test node'),
                    'base' => 'contenttypetest',
                    'module' => 'contenttypetest',
                    'description' => t("This nodetype is a test how to create nodetypes."),
                    'help' => 'So this is how your new contenttype looks!',
                    'title_label' => t('Test'),
                    'has_body' => FALSE,
                ),
            );
        }
    
    
        // hook_validate() implementation
        function contenttypetest_validate(){
        }
    
    ?>

    contenttypetest.install

    <?php
    
        // hook_uninstall() implementation
        function contenttypetest_uninstall(){
            node_type_delete('contenttypetest');
        }
    
    ?>
  • Fill array with server request URI strings

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    <?php
    
    $request = explode( "/", $_SERVER["REQUEST_URI"] );
    array_shift( $request );
    
    print_r( $requests );
    
    ?>
  • Render imagecache images

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    echo( "<img src=\"".image_style_url("thumbnail", $photo["uri"] )."\" alt=\"\"/>" );
  • Add unique IDs to menu items

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    <?php
    function HOOK_menu_link( array $variables ){
    
        $element = $variables['element'];
        $sub_menu = '';
        $name_id = strtolower(strip_tags($element['#title']));
    
        // remove colons and anything past colons
        if (strpos($name_id, ':')) $name_id = substr ($name_id, 0, strpos($name_id, ':'));
    
        //Preserve alphanumerics, everything else goes away
        $pattern = '/[^a-z]+/ ';
        $name_id = preg_replace($pattern, '', $name_id);
    
        $element['#attributes']['id'][] = 'menu-' . $element['#original_link']['mlid'] . ' '.$name_id;
    
        if( $element['#below'] )
            $sub_menu = drupal_render($element['#below']);
    
        $output = l($element['#title'], $element['#href'], $element['#localized_options']);
    
        return '' . $output . $sub_menu . "
  • \n"; } ?>
  • Obtain matching entities

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    function obtain_entities_by_type($entity_type,$bundle,$limit=10,$offset=0,$subject_nid=FALSE){
    
        $query=new EntityFieldQuery();
    
        $query->entityCondition('entity_type', $entity_type)
            ->entityCondition('bundle', $bundle)
            ->propertyCondition('status', 1)
            ->range($offset, $limit);
    
        if($subject_nid)
            $query->fieldCondition('field_subject','nid',$subject_nid);
    
        $results=$query->execute();
    
        if(array_key_exists('node',$results))
            return entity_load($entity_type,array_keys($results[$entity_type]));
    
    }

    Useage

    obtain_entities_by_type('node','page',10,0,432);

    Or

    <?php
    $sql="SELECT node.nid AS nid,
    node.title AS node_title,
    node.created AS node_created,
    node_data_field_weight.field_weight_value AS node_data_field_weight_field_weight_value
     FROM node node
     LEFT JOIN content_field_weight node_data_field_weight ON node.vid = node_data_field_weight.vid
     WHERE (node.status <> 0)
        ORDER BY node_data_field_weight_field_weight_value DESC";
    
    $db_query=db_query($sql);
    
    $items=array();
    while($row=db_fetch_array($db_query))
    	$items[]=array( $row["node_title"], $row["node_created"], $row["nid"], $row["node_data_field_weight_field_weight_value"] );
    
    echo("<pre>".print_r($items,TRUE)."</pre>\n\n");
    
    ?>

    Or

    <?php
    function snag_drupal_pages(){
        $sql_children="SELECT node.nid AS nid, node.vid AS node_vid, node.title AS node_title
         FROM node node
         WHERE node.type in ('page')";
        $db_query_children = db_query($sql_children);
        $pages=array();
        foreach($db_query_children as $row){
        	$nd=node_load($row->nid);
        	$key=array_push( $pages,array() ) - 1;
        	$pages[$key]["id"] = $row->nid;
        	$pages[$key]["title"] = $nd->title;
        	$pages[$key]["date"] = $nd->created;
        	if( drupal_lookup_path('alias',"node/".$nd->nid) ) $pages[$key]["path"] = drupal_lookup_path('alias',"node/".$nd->nid);
        	else $pages[$key]["path"] = "node/".$nd->nid;
        	if( !empty($nd->field_parent_page) ) $pages[$key]["group"] = $nd->field_parent_page["und"][0]["nid"];
        }
        #echo("<pre>");print_r($pages);echo("</pre>\n");
        return $pages;
    }
    ?>
  • Show field when a different selection is made on the same form

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    function HOOK_form_alter( &$form, &$form_state, $form_id ){
    
        if( $form_id == "user_register_form" || $form_id == "user_profile_form" ) {
    
    
            // Shows OTHER text field when 'Other' is selected as their specialty
    
            $form["field_specialty_other"]["#states"] = array(
                "visible" => array(
                    ':input[name="field_specialty[und]"]' => array("value"=>"Other"),
                )
            );
    
    
        }
    
    }
  • Insert email as username at registration

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    <?php
    function HOOK_user_insert( &$edit, &$account, $category = NULL ){
    
        // Don't create a new username if one is already set
        if( strpos($account->name, 'temporary_') !== 0)
            return;
    
        // Otherwise, replace username with email address field
        db_update("users")
            ->fields(array("name" => $edit["mail"]))
            ->condition("uid", $account->uid)
            ->execute();
    
        $edit["name"] = $edit["mail"];
        $account->name = $edit["mail"];
        return;
    }
    
    
    function HOOK_user_register_form_alter( &$form, &$form_state, $form_id ){
    
        $form["account"]["name"]["#value"] = "temporary_".user_password();
        $form["account"]["name"]["#access"] = FALSE;
    
    }?>
  • Login redirect

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    <?php
    
    function HOOK_user_login_submit( $form, &$form_state ){
        $form_state["redirect"] = "";
    }
    
    function HOOK_form_user_login_alter( &$form, $form_state ){
        $form["#submit"][] = "HOOK_user_login_submit";
    }
    
    ?>
  • Make Drupal Module Most Important

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    So other modules don't supersede your module, run this code once.
    <?php
    db_query("UPDATE {system} SET weight = 100 WHERE name = 'MODULE_NAME'");
    ?>
  • Image Desaturation Effect

    Context: 
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Attribute Type: 
    Types
    .box img{
     filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'>
      <filter id=\'grayscale\'>
       <feColorMatrix type=\'saturate\' values=\'0.5\'/>
      </filter>
     </svg>#grayscale");
     filter: gray alpha(opacity=50);
     -webkit-filter: grayscale(50%);
     -webkit-transform: translateZ(0);
    }
    .box img:hover{
     filter: url("data:image/svg+xml;utf8,<svg xmlns=\'http://www.w3.org/2000/svg\'>
      <filter id=\'grayscale\'>
       <feColorMatrix type=\'saturate\' values=\'1\'/>
      </filter>
     </svg>#grayscale");
     -webkit-filter: grayscale(0%);
    }
  • Slideshow

    Context: 
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics

    HTML

    <div id="photos_rotator">
     <ul>
      <li>
       <a href="/node/15">
        <span class="title">003</span>
       </a>
       <div class="rotator_full"><img src="003_0.jpg" alt=""/></div>
      </li>
      <li>
       <a href="/node/14">
        <span class="title">002</span>
       </a>
       <div class="rotator_full"><img src="002_0.jpg" alt=""/></div>
      </li>
      <li>
       <a href="/node/13">
        <span class="title">001</span>
       </a>
       <div class="rotator_full"><img src="001_0.jpg" alt=""/></div>
      </li>
     </ul>
    </div>

    JavaScript

    jQuery(function($){
    
    
    
    
        function processSlideshow( nextElem ){
            currentElem = $("#photos_rotator ul li.selected");
            if( !nextElem ){
                currentElemIndex = $("#photos_rotator ul li").index(currentElem);
                nextElem = $('#photos_rotator ul li').get(currentElemIndex+1);
                if( !nextElem ) nextElem = $("#photos_rotator ul li").get(0);
            }
            //fade out
            $(currentElem).removeClass("selected");
            $(currentElem).find(".rotator_full").css("left","-600px");
            setTimeout(function(){
                $(currentElem).find(".rotator_full").css("z-index","-2");
                $(currentElem).find(".rotator_full").css("left","600px");
            }, 700);
            //fade in
            $(nextElem).addClass("selected");
            $(nextElem).find(".rotator_full").css("z-index","-1");
            $(nextElem).find(".rotator_full").css("left","0");
        }
    
        if( $("#photos_rotator").length ){
            processSlideshow( $("#photos_rotator ul li").get(0) );
            setInterval(function(){ processSlideshow(); }, 6000);
            $("#photos_rotator ul li a").click(function(){
                processSlideshow( $(this).parent() );
                return false;
            });
        }
    
    
    
    
    });

    CSS

    #photos_rotator{
        position: relative;
        width: 600px;
        height: 400px;
        margin: 15px auto 0 auto;
        z-index: 0;
        overflow: hidden;
    }
    #photos_rotator ul{
        list-style: none;
        padding: 0;
        margin: 0;
        width: 300px;
    	padding: 370px 0 0 25px;
    }
    #photos_rotator ul:after{
        content: "";
        display: block;
        height: 0;
        clear: both;
    }
    #photos_rotator ul li{
        float: left;
        width: 30px;
        height: 30px;
    }
    #photos_rotator ul li a{
        display: block;
        height: 30px;
        line-height: 30px;
        text-align: center;
        text-decoration: none;
    }
    #photos_rotator ul li.selected a{
        background-color: #2bd06a;
        -webkit-transition: all 0.5s ease;
        -moz-transition: all 0.5s ease;
        -o-transition: all 0.5s ease;
        transition: all 0.5s ease;
    }
    
    #photos_rotator ul li .rotator_full{
        z-index: -1;
        position: absolute;
        top: 0;
        left: 600px;
        -webkit-transition: all 0.5s ease;
        -moz-transition: all 0.5s ease;
        -o-transition: all 0.5s ease;
        transition: all 0.5s ease;
    }
  • Webcam Image Refresher

    Context: 
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Attribute Type: 
    Types

    HTML

    <img src="http://orgnsm.org/camoff.jpg" alt="Webcam" id="webcamImage"/></div>

    JavaScript

    function refreshCam(id, file) {
    	var today = new Date();
    	var h = today.getHours();
    	var m = today.getMinutes();
    	var s = today.getSeconds();
    	document.getElementById(id).src = file + "?time="+h+m+s;
    	setTimeout('refreshCam("webcamImage","'+file+'")',10000);
    }
    
    window.onload = function(){
    
        if( document.getElementById("webcamImage") )
            refreshCam( "webcamImage","http://orgnsm.org/webcam.jpg" );
    
    }
  • AJAX Remote Read, Local Write

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics

    w/JavaScript

    //the callback function run after loading JSONp below
    function test_results_loaded(data){
    
     //post data to a service via ajax
     var xhr = new XMLHttpRequest();
     xhr.open("POST", "https://orgnsm@orgnsm.org:lkAGWUE01H@orgnsm.testrail.com//index.php?/api/v2/add_result/1", true);
     xhr.setRequestHeader('Content-Type', 'application/json;');
     xhr.setRequestHeader('Accept', 'application/json;');
    
     // send the collected data as JSON
     xhr.send(JSON.stringify({"status_id":"1"}));
    
     xhr.onloadend = function () { alert("Wrote test data"); };
    
    }
    
    
    
    window.onload = function(){
    
    
     //add event to a button that loads remote JSONp
    
     document.getElementById('loaderButton').onclick = function(){
      var script = document.createElement('script');
      script.src = 'http://shellfiche.anoml.net/test.php5?callback=test_results_loaded';
      document.getElementsByTagName('head')[0].appendChild(script);
     }
    
    
    }

    w/JQuery

    $(document).ready(function(){
    
    
     $("#loaderButton").click(function(){
    
      $.ajax({
       url: 'http://shellfiche.anoml.net/test.php5',
       dataType: "jsonp",
       jsonpCallback: "callback",
       success: function( testreply ){
        alert("Test results obtained.. Posting results...");
    
        $.ajax({
         url: 'https://orgnsm.testrail.com//index.php?/api/v2/add_result/1',
         username: "orgnsm@orgnsm.org",
         password: "lkAGWUE01H",
         contentType: "application/json;",
         accepts: "application/json;",
         dataType: "json",
         type: "POST",
         data: '{"status_id": "1"}',
         processData: "false",
         headers:{"Content-Type": "application/json;"},
         beforeSend: function(jqXHR){
          jqXHR.overrideMimeType("application/json;");
          jqXHR.setRequestHeader("Accept", "application/json;");
         },
         success: function( postreply ){
          alert("Wrote test data");
         }
        });
    
       }
      });
    
      return false;
    
     });
    
    
    });
  • DOM Inject and Add Event

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics

    w/JavaScript

    window.onload = function(){
    
     //create new button
     var btn = document.createElement("a");
     btn.setAttribute("id", "addedbutton");
     var btntxt = document.createTextNode("Run Me");
     btn.appendChild(btntxt);
    
     //inject new button
     document.getElementById("sidebar").appendChild(btn);
    
     //add event to new button
     document.getElementById('addedbutton').onclick = function(){
      alert("Success");
     }
    
    }

    w/JQuery

    $(document).ready(function(){
    
     var test = $("<a href='#'>Run Me</a>").click(function(){
      alert("Success");
      return false;
     });
    
     $("body").append(test);
    
    });
  • Pagination Logic

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Installation URL: 
    http://stage.orgnsm.org/code/pagination.php
    <?php
    
    $items = array(
        0 => array( "item 1", "2013-09-13", "1" ),
        1 => array( "item 2", "2013-09-14", "2" ),
        2 => array( "item 3", "2013-09-15", "3" ),
    );
    
    
    ######## CALCULATIONS #########
    
    # set per-page var
    if (isset($_GET["perpage"])) $perpage = $_GET["perpage"];
    else $perpage = 10;
    
    # calc numb of pages
    $pages = ceil(count($items) / $perpage);
    
    # which page are we on?
    if( isset($_GET["page"]) && round($_GET["page"]) <= $pages && round($_GET["page"]) > 0 )
    	$page = round($_GET["page"]);
    else $page = 1;
    
    # calc start and end item
    $startItem = (($page - 1) * $perpage);
    $endItem = $startItem + ($perpage - 1);
    if( $endItem > $items ) $endItem = $endItem - ($endItem % $items);
    
    
    
    
    
    ######## PRINT ITEMS #########
    
    echo( "<div>\n" );
    echo( " <ul>\n");
    
    for( $i=$startItem; $i<=$endItem; $i++ ){
    
    	echo( "  <li>\n");
    	echo( "   <a href=\"/node/".$items[$i][2]."\">\n");
    	echo( "    <span class=\"title\">" . $items[$i][0] . "</span>\n" );
    	echo( "   </a>\n" );
    	echo( "  </li>\n" );
    }
    
    echo( " </ul>\n" );
    echo( "</div>\n\n" );
    
    
    
    # print page links as: URL/?page=##
    
    echo("<ul class=\"pagination\">\n");
    
    if( $page > 1 )
    	echo(" <li>");
    	echo("  <a href=\"?page=".($page-1)."&perpage=".$perpage."\" class=\"previous\">Previous</a>");
    	echo(" </li>\n");
    
    for ($i=1; $i<=$pages; $i++) {
    	if ($i == $page) {
    		echo(" <li>");
    		echo("  <a href=\"?page=".$i."&perpage=".$perpage."\" class=\"active\">".$i."</a>");
    		echo(" </li>\n");
    	} else {
    		echo(" <li>");
    		echo("  <a href=\"?page=".$i."&perpage=".$perpage."\">".$i."</a>");
    		echo(" </li>\n");
    	}
    }
    
    if( $page < $pages )
    	echo(" <li><a href=\"?page=".($page+1)."\" class=\"next\">Next</a></li>\n");
    
    echo("</ul>\n\n");
    
    
    ?>
  • Device-Responsive Layout

    Context: 
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Attribute Type: 
    Types
    Installation URL: 
    http://code.orgnsm.org/viewport.html

    HTML

    <meta name="viewport" content="width=device-width, initial-scale=1.0;"/>

    CSS

    
    @media (max-width: 480px){
    }
    @media (max-width: 767px){
        #container{
            padding: 0 25px;
        }
        nav ul li a{
            font-size: 100%;
            padding: 15px 0;
            border-radius: 30px;
        }
        nav ul li a svg{
            width: 60px;
            height: 60px;
        }
    }
    @media (min-width: 768px) and (max-width: 979px){
        #container{
            padding: 0 35px;
        }
        nav ul li a{
            font-size: 120%;
            padding: 20px 0;
            border-radius: 40px;
        }
        nav ul li a svg{
            width: 80px;
            height: 80px;
        }
    }
    @media (max-width: 979px){
    }
    @media (min-width: 980px){
        /* default rules */
    }
    @media (min-width: 1200px){
        #container{
            padding: 0 75px;
        }
        nav ul li a{
            font-size: 170%;
            padding: 30px 0;
            border-radius: 60px;
        }
        nav ul li a svg{
            width: 133px;
            height: 133px;
        }
    }
  • Dynamic Form Submission

    Context: 
    Connection: 
    Attribute Type: 
    Types
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Connection: 
    Weight: 
    100
    Attribute Type: 
    Topics
    Installation URL: 
    http://stage.orgnsm.org/code/form.html

    The JavaScript

    jQuery(function($){
    
        $("#contact").submit(function(){
            //grab form values before blowing it out of the DOM in the next line
            values=$(this).serialize();
            $("#contact").html( "<p>Sending message...</p>\n" );
            //send the values to the PHP handler
            $.ajax({
                type: "POST",
                url: $("#contact").attr('action'),
                data: values,
                success: function(re){
                    $("#contact").html(re);
                }
            });
            return false;
        });
    
    });

    PHP

    <?php
    if( $_SERVER["REQUEST_METHOD"] == "POST" ){
        $to = "orgnsm@orgnsm.org";
        $subject = "Contact through website";
        $message = "Message: ".$_POST["message"]."\r\rFrom: ".$_POST["nombre"]."\r\rEmail: ".$_POST["email"];
        $from = $_POST["email"];
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
        echo( "<p>Your message has been sent. Thank you</p>\n" );
    }
    ?>

    HTML

    <form action="/sites/all/themes/visionarysports/contact.php" method="POST" id="contact">
     <div><input type="text" name="nombre" id="nombre" placeholder="Your Name"/></div>
     <div><input type="email" name="email" id="email" placeholder="Your E-mail"/></div>
     <div><textarea name="message" id="message" placeholder="Your Message"></textarea></div>
     <div><input type="submit" value="Send"/></div>
    </form>