Support

[sticky] [closed] WordPress Tips (241 posts)

Languages

de | fr | es | 日本語

About This Topic

Tags

  1. rss milo

    moderator


    rss Posted 2 years ago
    #

    Display the number of tweets for each page or post

    function tweetCount($url) {
    $content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
    $element = new SimpleXmlElement($content);
    $tweets = $element->story->url_count;
    echo $tweets." tweets!";
    }

    <?php tweetCount($post->permalink); ?>

  2. rss milo

    moderator


    rss Posted 2 years ago
    #

    Custom WP_Query Loop Working with Pagination and WP-PageNavi

    <?php
    $temp = $wp_query;
    $wp_query= null;
    $wp_query = new WP_Query('cat=-6&paged=' . $paged);
    while ($wp_query->have_posts()) : $wp_query->the_post();
    ?>

    <?php // the usual post-displaying codes here ?>

    <?php
    endwhile;
    if(function_exists('wp_pagenavi')) { wp_pagenavi(); }
    $wp_query = null; $wp_query = $temp; ?>

  3. rss milo

    moderator


    rss Posted 2 years ago
    #

    WordPress 2.9 add_theme_support

    // Load in support for template functions which the theme supports require_if_theme_supports( 'post-thumbnails', ABSPATH . WPINC . '/post-image-template.php'

    if ( function_exists( 'add_theme_support' ) ) add_theme_support( 'post-thumbnails' );

    <?php if ( has_post_image() ) : ?> < a href="<?php the_permalink(); ?>"><?php the_post_image( array( 75, 75 ), array( 'class' => 'alignleft' ) ); ?>< /a> <?php endif; ?>

  4. rss milo

    moderator


    rss Posted 2 years ago
    #

    WordPress 2.9 new excerpt filters

    // Changing excerpt length
    function new_excerpt_length($length) { return 40; } add_filter('excerpt_length', 'new_excerpt_length');
    // Changing excerpt more function new_excerpt_more($more) { return '...'; }
    add_filter('excerpt_more', 'new_excerpt_more');

  5. rss milo

    moderator


    rss Posted 2 years ago
    #

    Cleanup WordPress Header

    remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
    remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
    remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
    remove_action( 'wp_head', 'index_rel_link' ); // index link
    remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
    remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
    remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp

  6. rss milo

    moderator


    rss Posted 2 years ago
    #

    show WordPress post attachments

    $args = array(
    'post_type' => 'attachment',
    'numberposts' => null,
    'post_status' => null,
    'post_parent' => $post->ID );
    $attachments = get_posts($args);
    if ($attachments) {
    foreach ($attachments as $attachment) {
    echo apply_filters('the_title', $attachment->post_title); the_attachment_link($attachment->ID, false); } }

  7. rss milo

    moderator


    rss Posted 2 years ago
    #

    Display all thumbs related to a specific page on a media page in WordPress

    function wallthumb($id=false,$beforelist='< ul class="gallerythumb">',$afterlist='< /ul>',$beforeitem='< li>',$afteritem='< /li>'){
    global $wp_query;
    $goquery = $wp_query->post;
    if(is_attachment()){
    $ptitre = $goquery->post_title;
    $idparent = $goquery->post_parent;
    if(!$id){
    $id = $goquery->ID;
    }
    if($idparent == null || $idparent == '' || $idparent == 0){
    return;
    }
    //$twice = get_posts('post_type=attachment&post_mime_type=image&numberposts=-1&order=ASC&post_status=null&post_parent='.$idparent);
    $twice = get_children('post_type=attachment&post_mime_type=image&order=ASC&post_parent='.$idparent);//recup des infos des pièces jointes a la page parente
    $stocklienimage = array();
    if($twice){//si pièces jointes
    foreach ($twice as $value) {//boucle
    $classthumbactu = '';
    if($value->ID == $id){
    $classthumbactu=' thumbactu';
    }
    $stocklienimage[$value->ID] = $beforeitem.'< a class="wallthumb'.$classthumbactu.'" href="'.get_attachment_link($value->ID).'" title="'.wp_specialchars( get_the_title($value->ID), 1 ).'" rel="attachment">'.wp_get_attachment_image( $value->ID, 'thumbnail' ).'< /a>'.$afteritem;
    }
    }else{
    return;
    }
    echo $beforelist.implode('', $stocklienimage).$afterlist;
    }
    }

    <?php wallthumb() ?>

  8. rss milo

    moderator


    rss Posted 2 years ago
    #

    Extend the body_class function

    add_filter('body_class','top_level_parent_id_body_class');
    function top_level_parent_id_body_class($classes) {
    global $wpdb, $post;
    if (is_page()) {
    if ($post->post_parent) { $ancestors=get_post_ancestors($post->ID); $root=count($ancestors)-1;
    $parent = $ancestors[$root];
    } else {
    $parent = $post->ID; }
    $classes[] = 'top-level-parent-pageid-' . $parent; }
    return $classes; }

  9. rss milo

    moderator


    rss Posted 2 years ago
    #

    Automatically insert author bio on each post

    function get_author_bio ($content=''){
    global $post; $post_author_name=get_the_author_meta("display_name"); $post_author_description=get_the_author_meta("description"); $html="<div class='clearfix' id='about_author'>\n"; $html.="PG\n"; $html.="<div class='author_text'>\n"; $html.="<h4>Author: <span>".$post_author_name."</span></h4>\n"; $html.= $post_author_description."\n"; $html.="</div>\n"; $html.="<div class='clear'></div>\n"; $content .= $html; return $content; } add_filter('the_content', 'get_author_bio');

  10. rss milo

    moderator


    rss Posted 2 years ago
    #

    Hide login error messages

    add_filter('login_errors',create_function('$a', "return null;"));

  11. rss milo

    moderator


    rss Posted 2 years ago
    #

    title overwrite

    <?php $title = get_post_meta($post->ID, "custom-title", true); if ($title != "") { echo "<h1>".$title."</h1>"; } else { ?> <h1><?php the_title(); ?></h1> <?php } ?>

  12. rss milo

    moderator


    rss Posted 2 years ago
    #

    detect the visitor browser

    <?php add_filter('body_class','browser_body_class'); function browser_body_class($classes) { global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone; if($is_lynx) $classes[] = 'lynx'; elseif($is_gecko) $classes[] = 'gecko'; elseif($is_opera) $classes[] = 'opera'; elseif($is_NS4) $classes[] = 'ns4'; elseif($is_safari) $classes[] = 'safari'; elseif($is_chrome) $classes[] = 'chrome'; elseif($is_IE) $classes[] = 'ie'; else $classes[] = 'unknown'; if($is_iphone) $classes[] = 'iphone'; return $classes; } ?>

  13. rss milo

    moderator


    rss Posted 2 years ago
    #

    categories in two columns

    <?php $cats = explode("< br />",wp_list_categories('title_li=&echo=0&depth=1&style=none')); $cat_n = count($cats) - 1; for ($i=0;$i<$cat_n;$i++): if ($i<$cat_n/2): $cat_left = $cat_left.'< li>'.$cats[$i].'< /li>'; elseif ($i>=$cat_n/2): $cat_right = $cat_right.'< li>'.$cats[$i].'< /li>'; endif; endfor; ?> < ul class="left"> <?php echo $cat_left;?> < /ul> < ul class="right"> <?php echo $cat_right;?> < /ul>

  14. rss milo

    moderator


    rss Posted 2 years ago
    #

    tr.im urls for your blog posts

    function getTrimUrl($url) { $tinyurl = file_get_contents("http://api.tr.im/api/trim_simple?url=".$url); return $tinyurl; }

    <?php $turl = getTrimUrl(get_permalink($post->ID)); echo 'Short Url for this post: < a href="'.$turl.'">'.$turl.'< /a>' ?>

  15. rss milo

    moderator


    rss Posted 2 years ago
    #

    latest sticky posts

    <?php $sticky = get_option('sticky_posts'); rsort( $sticky ); $sticky = array_slice( $sticky, 0, 5); query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) ); ?>

  16. rss milo

    moderator


    rss Posted 2 years ago
    #

    insert content after each post

    function insertFootNote($content) { if(!is_feed() && !is_home()) { $content.= "<div class='subscribe'>"; $content.= "<h4>Enjoyed this article?</h4>"; $content.= "<p>Subscribe to our < a href='http://feeds2.feedburner.com/...'>RSS feed< /a> and never miss a recipe!</p>"; $content.= "</div>"; } return $content; } add_filter ('the_content', 'insertFootNote');

  17. rss milo

    moderator


    rss Posted 2 years ago
    #

    send your articles by email to their friends

    < a href="mailto:?subject=<?php the_title(); ?>&body=<?php the_permalink() ?>" title="Send this article to a friend!">Email this< /a>

  18. rss milo

    moderator


    rss Posted 2 years ago
    #

    Remove widget areas

    <?php add_filter( 'sidebars_widgets', 'disable_all_widgets' ); function disable_all_widgets( $sidebars_widgets ) { if ( is_home() ) $sidebars_widgets = array( false ); return $sidebars_widgets; } ?>

  19. rss milo

    moderator


    rss Posted 2 years ago
    #

    provide tinyurls

    function getTinyUrl($url) { $tinyurl = file_get_contents("http://tinyurl.com/api-create.php?url=".$url); return $tinyurl; }

    <?php $turl = getTinyUrl(get_permalink($post->ID)); echo 'Tiny Url for this post: < a href="'.$turl.'">'.$turl.'< /a>' ?>

  20. rss milo

    moderator


    rss Posted 2 years ago
    #

    Get parent page/post title

    <?php $parent_title = get_the_title($post->post_parent); echo $parent_title; ?>

  21. rss milo

    moderator


    rss Posted 2 years ago
    #

    privates pages in navigation menus

    < ul>
    <?php wp_list_pages('depth=1&title_li=0&sort_column=menu_order'); if(current_user_can('read_private_pages')) : ?>
    < li>
    < a href="<?php echo get_permalink(10); ?>">For Authors only< /a>
    < /li>
    <?php endif; ?>
    < /ul>

  22. rss milo

    moderator


    rss Posted 2 years ago
    #

    enlight searched text in search results

    echo $title;

    replaced with

    <?php $title = get_the_title(); $keys= explode(" ",$s); $title = preg_replace('/('.implode('|', $keys) .')/iu', '<strong class="search-excerpt">', $title); ?>

  23. rss milo

    moderator


    rss Posted 2 years ago
    #

    Remove /category/ from your WordPress url

    RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]

  24. rss milo

    moderator


    rss Posted 2 years ago
    #

    Embed CSS in your posts with a custom field

    <?php if (is_single()) { $css = get_post_meta($post->ID, 'css', true); if (!empty($css)) { ?> <style type="text/css"> <?php echo $css; ?> <style> <?php } } ?>

    insert the following code between the <head> and </head>

Topic Closed

This topic has been closed to new replies.

Design by milo

Milo designs web sites that strike the perfect balance between professional high-class graphics, functionality, usability, user experience, and high performance.