How To Disable WordPress RSS Feed
The following snippet will let you disable WordPress RSS feed.
1 2 3 4 5 6 7 8 9 10 11 |
/** * disable feed */ function fb_disable_feed() { wp_die( __('Kein Feed erreichbar, besuchen Sie doch bitte die <a href="'. get_bloginfo('url') .'">Startseite</a>!') ); } add_action('do_feed', 'fb_disable_feed', 1); add_action('do_feed_rdf', 'fb_disable_feed', 1); add_action('do_feed_rss', 'fb_disable_feed', 1); add_action('do_feed_rss2', 'fb_disable_feed', 1); add_action('do_feed_atom', 'fb_disable_feed', 1); |
Snippet Source/Credit: bueitge.de
How To Divide Posts From One Category Into Two Columns
Using the following snippet, you will be able to divide your posts from one category to two columns.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<?php // loop only artists posts global $post; // required $category_id = ( get_cat_ID( 'Teksty' ) ); $args = array( 'category' => $category_id, 'numberposts' => -1, ); $custom_posts = get_posts($args); $count = count( $custom_posts ); // only if more posts if( $count > 1) { // column one $col1_count = ceil( $count/2 ); $col1 = array_slice( $custom_posts, 0, $col1_count ); // column 2 $col2_count = ($count - $col1_count); $col2 = array_slice( $custom_posts, -$col2_count ); } else { $col1 = &$custom_posts; $col2 = array(); } // col1 ?> <div id="column-1"> <?php foreach($col1 as $post) : setup_postdata($post); ?> <?php include (TEMPLATEPATH . '/inc/text-list-item.php'); ?> <?php endforeach; ?> </div><!-- #column-1 --><div id="column-2"> <?php foreach($col2 as $post) : setup_postdata($post); ?> <?php include (TEMPLATEPATH . '/inc/text-list-item.php'); ?> <?php endforeach; ?> </div><!-- #column-2 --> |
Snippet Source/Credit: Snipplr
How To Get All WordPress Post Meta
The following snippet will let you get all WordPress post meta.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
function get_post_meta_all($post_id){ global $wpdb; $data = array(); $wpdb->query(" SELECT `meta_key`, `meta_value` FROM $wpdb->postmeta WHERE `post_id` = $post_id "); foreach($wpdb->last_result as $k => $v){ $data[$v->meta_key] = $v->meta_value; }; return $data; } |
Snippet Source/Credit: Snipplr
How To Include Page Within Another Page
Using the following snippet will let you include page within another page.
1 2 3 4 5 6 7 8 9 10 |
//Add to functions.php function show_post($path) { $post = get_page_by_path($path); $content = apply_filters('the_content', $post->post_content); echo $content; } //add to your page/post/template file <?php show_post('about'); // Shows the content of the "About" page. ?> <?php show_post('category/postname'); // Shows content of a Post page. ?> |
Snippet Source/Credit: Snipplr
How To List Current Post Taxonomies And Terms
Using the following snippet, you will be able to list all the current post taxonomies and terms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
//To list FULL custom taxonomy <?php $taxonomy = 'replace_this_with_taxonomy_name'; $queried_term = get_query_var($taxonomy); $terms = get_terms($taxonomy, 'slug='.$queried_term); if ($terms) { echo '<ul>'; foreach($terms as $term) { echo '<li><a href="'.get_term_link($term->slug, $taxonomy).'">'.$term->name.'</a></li>'; } echo '</ul>'; } ?> //To list ONLY custom taxonomy associated with post: //non-linking, list only: <?php $terms = wp_get_post_terms($post->ID,'replace_this_with_taxonomy_name'); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug, 'replace_this_with_taxonomy_name').'">'. $term->name . "</a></li>"; } echo "</ul>"; }?> //links to taxonomy archive: <?php $terms = wp_get_post_terms($post->ID,'replace_this_with_taxonomy_name'); $count = count($terms); if ( $count > 0 ){ echo "<ul>"; foreach ( $terms as $term ) { echo '<li><a href="'.get_term_link($term->slug, 'replace_this_with_taxonomy_name').'">'. $term->name . "</a></li>"; } echo "</ul>"; }?> |
Snippet Source/Credit: Snipplr