3809 readersThe post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting:
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<!-- Post stuff -->
</div>
I was in a circumstance where I wanted to add an additional class to what that
2692 readersWe covered how to run a shortcode in a widget. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably
8208 readers
( example screenshot )PHP
add_action("admin_init", "pdf_init");
add_action('save_post', 'save_pdf_link');
function pdf_init(){
add_meta_box("my-pdf", "PDF Document", "pdf_link", "post", "normal", "low");
}
function pdf_link(){
global $post;
$custom = get_post_custom($post->ID);
$link = $custom["link"][0];
$count = 0;
echo '';
$query_pdf_args = array(
'post_type' => 'attachment',
'post_mime_type' =>'application/pdf',
'post_status' => 'inherit',
'posts_per_page' => -1,
);
$query_pdf = new WP_Query( $query_pdf_args );
$pdf = array();
echo '';
echo 'SELECT pdf FILE';
foreach ( $query_pdf->posts as $file) {
2106 readersWordPress wp_nav_menu function is really helpful to display a custom navigation menu in your theme. Today's hack will automatically add a "home" link to your menu.Looking for WordPress hosting? Try WP Web Host. Prices starts at $5/month and you can try it for free!How to show the “home” link on wp_nav_menu default fallback function
3940 readersIn a recent post, we show you how to clean up and enhance the functionality of WordPress with a custom functions.php template. In that post, we explain how using a custom functions.php template can speed up development while optimizing many key aspects of WordPress. In this post, we deliver another prime collection of 15 custom
7130 readers
PHP
add_filter( 'getarchives_where' , 'ucc_getarchives_where_filter' , 10 , 2 );
function ucc_getarchives_where_filter( $where , $r ) {
$args = array( 'public' => true , '_builtin' => false );
$output = 'names'; $operator = 'and';
$post_types = get_post_types( $args , $output , $operator );
$post_types = array_merge( $post_types , array( 'post','CUSTOM_POST_TYPE_NAME' ) );
$post_types = "'" . implode( "' , '" , $post_types
3419 readersThe default output for WordPress’ post_class template tag includes class names for just about every type of page view imaginable:
page-parent
search-results
logged-in
author
paged
Plus just about everything else except for category ID information. It gives some good category-specific class names, but nothing to represent the category ID. For example, including the post_class function like this in your markup:
<div <?php
4208 readersBy default, when the blog admin left a comment on his blog, WordPress use the name in the comment css class. This is useful for styling, but it will also let people know about your admin login name. If you want to hide this info, read this recipe.Looking for WordPress hosting? Try WP Web Host.
3012 readers On day 9 of our Advents Calendar we show a custom pagination function which allows a user to insert custom next, previous or numbered page links into a post. Use the follow code for an custom plugin or insert the function in your theme, inside the functions.php. Please see the second code-area for an
8467 readers
PHP
function top_comment_authors($amount = 5) {
global $wpdb;
$results = $wpdb->get_results('
SELECT
COUNT(comment_author_email) AS comments_count, comment_author_email, comment_author, comment_author_url
FROM '.$wpdb->comments.'
WHERE comment_author_email != "" AND comment_type = "" AND comment_approved = 1
GROUP BY comment_author_email
ORDER BY comments_count DESC, comment_author