WordPress building blocks
1.2K views | +0 today
Follow
Your new post is loading...
Your new post is loading...
Scooped by Lisa Risager
Scoop.it!

List Posts, Highlight Current | CSS-Tricks

<?php if ( $post->ID == $wp_query->post->ID ) { echo ' class="current"'; } else {} ?>

 

 

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

How to use Read More in Pages « WordPress Codex

<?php global $more; $more = 0; ?> //The code must be inserted ahead of the call the_content, but AFTER the_post() <?php the_content('Continue Reading'); ?>
Lisa Risager's insight:

Please remember that the "Read More" tag is used only on the Home page which shows the latest posts. It does not work in "Pages". If you want to turn it on in Pages too for showing a set of partial posts, use the following code inside the loop for the dynamic content:

 
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Reference/previous post link within same category ı WordPress Codex

  <?php previous_post_link('%link', 'Previous in category', TRUE); ?>

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Function Reference/is post type archive « WordPress Codex

Determine if the current page is an archive made by a custom post type and display the custom post type title:

<?php if ( is_post_type_archive() ) {  ?> <h1><?php post_type_archive_title(); ?></h1> <?php } ?>
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

WordPress: Get Tags for a Specific Category

$custom_query = new P_Query('posts_per_page=-1&category_name=blog');

if ($custom_query->have_posts()) : while ($custom_query->have_posts()) : $custom_query->the_post();

$posttags = get_the_tags();

if ($posttags) {

foreach($posttags as $tag) { $all_tags[] = $tag->term_id; }

}

endwhile;

endif;

$tags_arr = array_unique($all_tags);

$tags_str = implode(",", $tags_arr);

$args = array( '

smallest' => 12,

'largest' => 12,

'unit' => 'px',

'number' => 0,

format' => 'list',

'include' => $tags_str );

wp_tag_cloud($args);

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

List posts in current category

<?php global $post;
$categories = get_the_category();
foreach ($categories as $category) ; ?>
<ul>
<?php $posts = get_posts('category=' . $category->term_id);
foreach ($posts as $post) : ?>
<li><a href="<?php the_permalink(); ?>"
title="<?php the_title(); ?>"><?php
the_title(); ?></a></li>
<?php endforeach; ?>
</ul>

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Remove before gallery | WPExplorer

/*--------------------------------------*/ /*    Clean up Shortcodes /*--------------------------------------*/ function wpex_clean_shortcodes($content){        $array = array (         '<p>[' => '[',         ']</p>' => ']',         ']<br />' => ']'     );     $content = strtr($content, $array);     return $content; } add_filter('the_content', 'wpex_clean_shortcodes');
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

List Categories with descriptions | WordPress Codex

This example will list in alphabetic order, all categories presented as links to the corresponding category archive. Each category descripition is listed after the category link.<?php $args=array( 'orderby' => 'name', 'order' => 'ASC' ); $categories=get_categories($args); foreach($categories as $category) { echo '<p>Category: <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a> </p> '; echo '<p> Description:'. $category->description . '</p>'; echo '<p> Post Count: '. $category->count . '</p>'; } ?>


more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Force sub-categories to use the parent category template | WerdsWords

// Filter to hide protected posts function exclude_protected($where) { global $wpdb; return $where .= " AND {$wpdb->posts}.post_password = '' "; } // Decide where to display them function exclude_protected_action($query) { if( !is_single() && !is_page() && !is_admin() ) { add_filter( 'posts_where', 'exclude_protected' ); } } // Action to queue the filter at the right time add_action('pre_get_posts', 'exclude_protected_action');
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Display scheduled posts | Keith Millington

<?php $my_query = new WP_Query('post_status=future&order=ASC'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Add Author Info to Single Post

<?php if (function_exists('get_avatar')) { echo get_avatar( get_the_author_meta('email'), '180, 220' ); }?>


<h3><?php the_author_posts_link(); ?></h3>
<p><?php the_author_meta('description'); ?></p>

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

WordPress functions to supercharge your Theme! • Yoast

// Allow HTML in user profiles remove_filter('pre_user_description', 'wp_filter_kses');
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Content in Multiple Columns

Content in Multiple Columns | WordPress building blocks | Scoop.it

This technique creates columns based on multiple instances of the <!--more--> tag. There are several caveats, so check the orginal article for all the details.

Here are the steps involved in implementing this technique:

Add the my_multi_col_v2 function to your functions.php fileAdd another snippet to your theme template file, for example page.phpAdd some CSS to format the markup into columnsAdd a couple of <!--more--> tags in your post or page to create the three columns
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Allow SVG through WordPress Media Uploader | CSS-Tricks

function cc_mime_types($mimes) { $mimes['svg'] = 'image/svg+xml'; return $mimes; } add_filter('upload_mimes', 'cc_mime_types');

 

 

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Excerpts/Read More on pages ı WordPress Codex

<?php global $more; $more = 0; ?>
Lisa Risager's insight:

You need to turn it on for pages!

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Hide Content on Password Protected Pages

Hide Content on Password Protected Pages | WordPress building blocks | Scoop.it

<?php if(!post_password_required()) { get_sidebar(); } ?>

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Multiple the_date() functions return empty date | Digging Into WordPress

Specifically, if there are two posts published on the same day, the second one will return nothing for a date.

 

To fix this, use the_time() instead.

Lisa Risager's insight:

the_time('j. F Y')

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

More tag ignored on home page | WordPress › Support

The problem is that you are putting the code in the wrong place. You are putting the code after the call to write the content instead of before. Try:

 

"<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php global $more; $more = 0; ?> <div class="post" id="post-<?php the_ID(); ?>"> <div class="entry"> <?php the_content('Read the rest of this entry &raquo;'); ?> </div>"
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

get_the_taxonomies

In WP 3.1, you can modify the template simply by passing it as a parameter:

the_taxonomies( array('before'=>'<ul><li>','sep'=>'</li><li>','after'=>'</li></ul>','template'=>'%s: %l'));

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Remove "No Categories" when no posts in category

<?php wp_list_categories('include=5&title_li=&show_option_none='); ?>

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Disable WordPress Feed | WP Engineer

/** * disable feed */function fb_disable_feed(){ wp_die( __('No feed available,please visit our <a href="'. get_bloginfo('url').'">homepage</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);
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Show Home Page Link in Menu

function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Track post views without a plugin | WordPress Snippets

Track post views without a plugin  | WordPress Snippets | WordPress building blocks | Scoop.it

Add this snippet into the functions.php of your wordpress theme then follow step 1. and step 2. to display the number of views for each post.

more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Wordpress Change the author slug | WordPress Snippets

Wordpress Change the author slug | WordPress Snippets | WordPress building blocks | Scoop.it
add_action('init','cng_author_base');
function cng_author_base(){
    global $wp_rewrite;
    $author_slug ='profile';// change slug name
    $wp_rewrite->author_base = $author_slug;
}
more...
No comment yet.
Scooped by Lisa Risager
Scoop.it!

Google Web Fonts

Add to functions.php:

 

/**
* Add Google Web Fonts
*/
function load_fonts() {
wp_register_style('googleFonts', 'http://fonts.googleapis.com/css?family=Allerta+Stencil');
wp_enqueue_style( 'googleFonts');
}

add_action('wp_print_styles', 'load_fonts');

 

 

Lisa Risager's insight:

 

Add styling.

more...
No comment yet.