Latest 100 public
snipts » wordpress
showing 1-20 of 161 snipts for wordpress
-
∞ Get Template Directory
<?php bloginfo( 'template_directory' ); ?>
-
∞ Blog home and site address
define('WP_HOME', 'http://digwp.com'); // no trailing slash define('WP_SITEURL', 'http://digwp.com'); // no trailing slash
-
∞ Shotcode: Show Related Posts (based on tags)
<?php function related_posts_shortcode( $atts ) { extract(shortcode_atts(array( 'limit' => '5', ), $atts)); global $wpdb, $post, $table_prefix; if ($post->ID) { $retval = '<ul>'; // Get tags $tags = wp_get_post_tags($post->ID); $tagsarray = array(); foreach ($tags as $tag) { $tagsarray[] = $tag->term_id; } $tagslist = implode(',', $tagsarray); // Do the query $q = "SELECT p.*, count(tr.object_id) as count FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p WHERE tt.taxonomy ='post_tag' AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id = p.ID AND tt.term_id IN ($tagslist) AND p.ID != $post->ID AND p.post_status = 'publish' AND p.post_date_gmt < NOW() GROUP BY tr.object_id ORDER BY count DESC, p.post_date_gmt DESC LIMIT $limit;"; $related = $wpdb->get_results($q); if ( $related ) { foreach($related as $r) { $retval .= ' <li><a title="'.wptexturize($r->post_title).'" href="'.get_permalink($r->ID).'">'.wptexturize($r->post_title).'</a></li> '; } } else { $retval .= ' <li>No related posts found</li> '; } $retval .= '</ul> '; return $retval; } return; } add_shortcode('related_posts', 'related_posts_shortcode'); /* * Usage: * [related_posts] * [related_posts limit="x"] to show a number of your choosing * Credit goes to Blue Anvil (http://blue-anvil.com/archives/8-fun-useful-shortcode-functions-for-wordpress/). */ ?>
-
∞ wordpress get posts
<?php function getPosts($path, $number) { $posts = array(); $buffer = file_get_contents($path); // Create a new SimpleXML string $xml = new SimpleXMLElement($buffer); // extract the information we want $channel = $xml -> channel; $count = $number; $i = 1; foreach ($channel->item as $post) { if ($i > $count) break; $posts = array( 'title' => $post->title, 'link' => $post->link ); $i++; } return $posts; }
-
∞ Functions.php Framework
<?php // -------------- Add support for nav menus -------------- add_theme_support( 'nav-menus' ); register_nav_menus( array( 'header' => __( 'Header Menu'), ) ); // -------------- Add support for gallery post thumbnails -------------- add_theme_support( 'post-thumbnails'); set_post_thumbnail_size( 310, 650); add_image_size( 'col1', 135, 650); // smart jquery inclusion if (!is_admin()) { wp_deregister_script('jquery'); wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false); wp_enqueue_script('jquery'); } // enable threaded comments function enable_threaded_comments(){ if (!is_admin()) { if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) wp_enqueue_script('comment-reply'); } } add_action('get_header', 'enable_threaded_comments'); // no more jumping for read more link function no_more_jumping($post) { return '<a href="'.get_permalink($post->ID).'" class="read-more">'.'Continue Reading'.'</a>'; } add_filter('excerpt_more', 'no_more_jumping'); ?>
-
∞ Redirect to first child page
<?php /* Template Name: Parent */ if (have_posts()) { while (have_posts()) { the_post(); $pagekids = get_pages("child_of=".$post->ID."&sort_column=menu_order"); $firstchild = $pagekids[0]; wp_redirect(get_permalink($firstchild->ID)); } } ?>
-
∞ Getting rid of the 'allowed tags' in Wordpress comment forms.
<?php comment_form(array('comment_notes_after' => '')); ?>
-
∞ Modify the_excerpt() output
<?php function my_excerpt_length($text){ return 10; } add_filter('excerpt_length', 'my_excerpt_length'); function new_excerpt_more($more) { return '...'; } add_filter('excerpt_more', 'new_excerpt_more'); ?>
-
∞ wordpress display custom value
<?php $values = get_post_custom_values('image'); echo $values[0]; ?>
-
∞ Get unique salts for a WP installation
curl https://api.wordpress.org/secret-key/1.1/salt/ > salt.txt
-
∞ Return post_thumbnail URL
<?php $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'medium'); // Returns the URL for the "Medium" post thumbnail echo $thumbnail[0]; ?>
-
∞ worrdpress loop
/*THE LOOP - START*/ <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> /*THE LOOP - END*/ <?php endwhile; else: ?> <p><?php _e('Sorry, no posts matched your criteria.'); ?></p> <?php endif; ?>
-
∞ removes heading in list pages
<ul> <?php wp_list_pages('title_li='); ?> </ul>
-
∞ adds first-page-item class to first item in list-pages
<?php function add_markup_pages($output) { $output= preg_replace('/page-item/', ' first-page-item page-item', $output, 1); $output=substr_replace($output, " last-page-item page-item", strripos($output, "page-item"), strlen("page-item")); return $output; } add_filter('wp_list_pages', 'add_markup_pages'); ?>
-
∞ Get WordPress page slug
// Add to functions.php function the_slug() { $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; return $slug; } // Add within the Loop <?php echo the_slug(); ?>
-
∞ Changing the post type on the home page
<?php add_filter( 'pre_get_posts', 'my_get_posts' ); function my_get_posts( $query ) { if ( is_home() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'post', 'page', 'album', 'movie', 'quote', 'attachment' ) ); return $query; } ?>
-
∞ query custom post types
<ul> <?php global $wp_query; $wp_query = new WP_Query("post_type=albums&post_status=publish"); while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul>
-
∞ Custom post types with custom taxonomies in wordpress3
<?php function post_type_albums() { register_post_type( 'albums', array('label' => __('Albums'), 'public' => true, 'show_ui' => true, 'supports' => array( 'post-thumbnails', 'excerpts', 'trackbacks', 'comments') ) ); // Adding the Custom Taxonomy for Genres. Here we can create categories specific for this post type. register_taxonomy( 'genres', 'albums', array( 'hierarchical' => true, 'label' => __('Genres') ) ); // Adding the Custom Taxonomy for Performer. Here we can add tags specific for this post type. register_taxonomy( 'performer', 'albums', array( 'hierarchical' => false, 'label' => __('Performer'), 'query_var' => 'performer', 'rewrite' => array('slug' => 'performer' ) ) ); } add_action('init', 'post_type_albums'); ?>
-
∞ create a custom post type in wordpress3
<?php $args = array( 'label' => __('Products'), 'singular_label' => __('Product'), 'public' => true, 'show_ui' => true, 'capability_type' => 'page', 'hierarchical' => false, 'rewrite' => true, 'query_var' => 'products', 'supports' => array('title', 'thumbnail') ); register_post_type( 'product' , $args ); ?>
-
∞ WordPress category
<?php //WordPress categorie parent binnenhalen $category = get_the_category(); $parent = get_cat_name($category[0]->category_parent); $parentID = get_cat_ID($parent); ?>


