Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Custom Plugin for Clients

<?php
/*
 * Plugin Name: Client Plugin
 * Plugin URI: http://webdesign.com
 * Description: Custom Plugin for Clients
 * Version: 1.0
 */

function wdc_create_widget_area(){
register_sidebar( array(
'name' => 'Widget Staging',
'id' => 'customer_widget',
'description' => 'Customize your Widgets here before going live.',
'before_widget' => '<div>',
'after_widget' => '</div>',
'before_title' => '<h2 class="customer-title">',
'after_title' => '</h2>'
)
);
}
add_action('widgets_init', 'wdc_create_widget_area');

add_filter('admin_footer_text', 'wdc_custom_footer');
function wdc_custom_footer(){
echo 'Theme and Site Development by Bob Bobertson.  Learn more at <a href="http://bobbobertson.com">http://bobbertson.com</a>.';
}

add_filter('default_content', 'custom_writing_helps');
function custom_writing_helps($content){
global $post_type;
if ($post_type == "post"){

$contentHelp = array(
0 => "Your Blog is Haunted",
1 => "I hacked your site"
);
return $contentHelp[array_rand($contentHelp)];
}
}

add_action('admin_head', 'excerpt_textarea_height');
function excerpt_textarea_height(){
echo '
<style type="text/css">
#excerpt{height:350px;}
</style>
';
}









How To Add visual composer support to WP Touch Theme

function add_js_script () {
    wp_enqueue_script( "js_script", plugins_url()."/js_composer/assets/js/js_composer_front.js" );
   wp_enqueue_style( "js_script", plugins_url()."/js_composer/assets/css/js_composer_front.css" );
}

add_action( 'wp_enqueue_scripts', 'add_js_script' );

Wordpress get/insert post attachments at custom size linked to custom size

<?php
// To insert custom loop of post attachments as images (at core or custom size) linked not to full size image but custom-configured (or core) size.

$postID = $post->ID;
//print_r($product_meta);

// (thumbnail, medium, large or full) or a 2-item array
// representing width and height in pixels, e.g. array(32,32)
// OR the custom config'd name of image size
$image_size = 'prods-large'; // the image size to be shown initially (smaller version)
$image_size_lg = 'large'; // the image size to link to (large version)

$images = get_children(array(
'post_parent' => $postID,
'post_type' => 'attachment',
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'menu_order',
//'exclude' => get_post_thumbnail_id(), -- uncomment to exclude post thumbnail
'post_mime_type' => 'image',
)
);

//print_r($images);
if($images) {

echo '<div class="prod-imgs">';

foreach( $images as $image ) {

$attachment_id = $image->ID;

// get the 'large' size image's URL
$image_attributes = wp_get_attachment_image_src( $attachment_id, 'large' ); // returns an array - [0] is the URL of the image 'large' size
$largeSizeURL = $image_attributes[0];

echo '<a class="attachment-' . $attachment_id . ' popup-with-zoom-anim img-link" href="' . $largeSizeURL . '">';
echo wp_get_attachment_image($attachment_id, $image_size);
echo '</a>';

}
echo '</div>';
}
?>

php array()

<?php
$identity = array(
        "name" => "Sam",
        "age"  => "47",
        "country" => "USA"
                );
?>

extract function use case

<?php
extract($identity); //var_dump(extract($identity)) == int 3
?>

wordpress sort by post view

<?php
   $args = array(
               'orderby'      => 'meta_value',
               'meta_key'     => 'post_views_count',
               'order'        => 'DESC',
               'post_status'  => 'publish'
           );
   $ranking = 0;
?>
<?php query_posts($args); ?>
<?php if ( have_posts() ) : ?>
     <?php while ( have_posts()) : the_post();
           $ranking++; ?>
               
               
          <!-- HTML -->
         
          <?php endwhile; else: ?>
<?php endif; ?>

information about a file path

<?php
$path_parts = pathinfo('/www/htdocs/inc/lib.inc.php');

echo $path_parts['dirname'], "\n";   // /www/htdocs/inc
echo $path_parts['basename'], "\n";  // lib.inc.php
echo $path_parts['extension'], "\n"; // php
echo $path_parts['filename'], "\n"; // since PHP 5.2.0   // lib.inc
?>