Skip to content

Instantly share code, notes, and snippets.

@ElmahdiMahmoud
ElmahdiMahmoud / gist:8451662
Created January 16, 2014 08:42
js: hide a DIV when the user clicks outside of it
$(document).mouseup(function (e)
{
var container = $("YOUR CONTAINER SELECTOR");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});
@ElmahdiMahmoud
ElmahdiMahmoud / gist:7482791
Created November 15, 2013 11:16
wp: item-gallery
<div class="item-gallery">
<?php query_posts('category_name=CATEGORY-NAME&posts_per_page=1'); ?>
<?php while (have_posts()) : the_post(); ?>
<div class="view">
<?php the_post_thumbnail(); ?>
</div>
<div class="thumbnail">
<ul>
<li>
<?php $meta = get_post_meta($post->ID, 'thumbnail' ); ?>
@ElmahdiMahmoud
ElmahdiMahmoud / gist:7413590
Created November 11, 2013 14:00
jquery: textarea resize
$('.resizeme').keydown(function(){
var contents = $(this).val();
var charlength = contents.length;
newwidth = charlength*8;
$(this).css({width:newwidth});
});
//example <input type="text" class="resizeme" value="stuff goes here!"/>
@ElmahdiMahmoud
ElmahdiMahmoud / gist:7331967
Created November 6, 2013 06:45
wp: if post has thumb
<?php
if ( '' != get_the_post_thumbnail() ) {
?>
<!-- HTML CODE GOES HERE -->
<?php
}
else {
?>
<!-- HTML CODE GOES HERE -->
<?php
@ElmahdiMahmoud
ElmahdiMahmoud / gist:7248642
Created October 31, 2013 12:10
wp: Get post views
<?php
/* functions.php */
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
@ElmahdiMahmoud
ElmahdiMahmoud / gist:7192808
Last active December 26, 2015 18:09
wp: get page content by ID
<?php
$id = #;
$post = get_page($id);
$content = apply_filters('the_content', $post->post_content);
echo $content;
?>
@ElmahdiMahmoud
ElmahdiMahmoud / gist:7192733
Last active December 26, 2015 18:09
wp: get page thumbnail
<?php echo get_the_post_thumbnail( $id, 'full' ); ?>
@ElmahdiMahmoud
ElmahdiMahmoud / gist:7151968
Created October 25, 2013 09:21
wp: if excerpt is empty
<?php if(!empty($post->post_excerpt)) {the_excerpt(); } ?>
@ElmahdiMahmoud
ElmahdiMahmoud / gist:6936215
Created October 11, 2013 15:01
php: email html template
<form method="post">
<input type="hidden" name="url" />
<ul>
<li>
<input class="w-90p" type="text" placeholder="Email" name="email" id="emailAddress" />
</li>
<li>
<textarea class="w-90p" name="message" placeholder="Write something..." id="messageText"></textarea>
</li>
@ElmahdiMahmoud
ElmahdiMahmoud / gist:6931201
Last active December 25, 2015 06:19
wp: Character limit count
<?php echo substr(strip_tags($post->post_content), 0, 150);?>