Tagged: wordpress Toggle Comment Threads | Keyboard Shortcuts

  • levin 8:16 pm on April 22, 2011 Permalink | Reply
    Tags: , wordpress   

    Rename Post format string in WordPress theme 

    Code

    Because post format string is hard coded in post.php, so you can’t change them in filter way. To rename the post format string and display in a theme, you can add the following function in function.php.

    function post_format_nicename() {
    		global $post;
    		$slug = str_replace('post-format-', '', get_post_format($post->ID));
    		if(empty($slug)) {
    				$slug = 'standard';
    		} 
    		$source = array('Standard', 'Status');
    		$replacement = array(__('Blog Post', 'textdomain'),__('Status Update','textdomain'));
    		$strings = str_replace($source, $replacement, get_post_format_strings());
            $string = $strings[$slug];
    		return $string;
    }
    
    
    

    To display the mod-ed post formant name, call this function

    
    echo post_format_nicename();
    
    
     
  • levin 9:08 pm on April 15, 2011 Permalink | Reply
    Tags: , wordpress   

    How to filter “Standard” Post format in WordPress 

    Post format

    As you know Post Formats is a theme feature introduced with Version 3.1. A Post Format is a piece of meta information that can be used by a theme to customize its presentation of a post. The Post Formats feature provides a standardized list of formats that are available to all themes that support the feature. There are new template tag to play with post_format as below

    WordPress Codex

    However, when you try to implement post_format, usually you’ll try to sort out the posts for each formats. For example, show all images format.

    <a href="<?php echo get_post_format_link('image');?>">
    Show Image Posts
    </a>
    

    The above code do present a link taking you to post_fomart archives page, pretty easy right? So… how about display the standand post? Unfortunately, there is no out of box function to do that. Let’s work it out.

    functions.php

    Setup theme support in functions.php, I put the post formats in vars, because we need to reused them in some place within the theme. Additionally, I created another function to register query variable to handle new query for standard post format.

    /* Register Query Variables*/
    add_filter('query_vars', 'my_queryvars' );
    function my_queryvars( $qvars )
    {
    $qvars[] = 'filter';
    return $qvars;
    }
    /* Post formats support */
    $my_post_formats = array( 'status','aside','image', 'gallery', 'link', 'video', 'audio' );
    foreach ($my_post_formats as $shortname) {
    	$my_post_formats_longname[] = 'post-format-'.$shortname;
    }
    add_theme_support( 'post-formats', $my_post_formats );
    

    The filter links

    <a href="<?php echo add_query_arg( 'filter','standard',remove_query_arg('post_format'));?>"><?php echo get_post_format_string('');?></a>
    <?php global $my_post_formats; foreach ($my_post_formats as $postformat) { ?>
    	| <a href="<?php echo get_post_format_link($postformat);?>"><?php echo get_post_format_string(str_replace('post-format-', '', $postformat) ); ?></a>
    <?php } ?>
    

    the loop

    Put the following code before the loop. This is a new taxonomy query since WordPress 3.0, it allows you to setup own query by taxonomy terms. And you may notice that I’ve put “NOT IN” operator to filter out standard posts. It is because “standard” post do not have post-format- taxonomy. The first condition to determine the from the $_GET request.

    <?php if(get_query_var('filter') == "standard") { 	global $my_post_formats_longname; 	$args = array( 			'tax_query' =--> array(
    			array( 'taxonomy' => 'post_format',
    				  'field' => 'slug',
    				  'terms' => $my_post_formats_longname,
    				  'operator' => 'NOT IN'
    				  )
    			)
    	);
    	query_posts( $args );
    }
    ?>
    

    That’s it

    Btw, I hope there have a better solution in future WordPress release. Thanks for reading!

     
  • levin 8:08 am on April 9, 2011 Permalink | Reply
    Tags: theme, wordpress   

    WordPress theme preview “The eVol Theme” 

    I’ll release this WordPress theme “The eVol Theme” for free(hopefully) in coming days(hopefully too), this theme is a all-in-one package build for photographers, portfolio users, bloggers.

    The themes support the follow key features.

    • Front-end composing
    • Auto image resize, attach
    • Exif, Geo location display for images.
    • Jplayer support for Audio/Video
    • Switchable index page style, Wall style or Post-it style.
    • Selectable front page slider effects.
    • Simple “likes” function.

    and more…

    Stay tuned, please follow @levindecaro

     
  • levin 7:18 pm on March 29, 2011 Permalink | Reply
    Tags: , wordpress   

    Submitting WordPress post from frontend without a plugin 

    Screen Shot

    Screen Shot

    About

    This tutorial will guide you to create your own custom post composing form to enable fast blogging with your favorite theme without adding a plugin. I’m looking for any alternative to not porting P2, however…. none.,  finally that’s the reason i wrote it, and It was also inspired by the original development from http://wpshout.com/wordpress-submit-posts-from-frontend/.

    Why

    I found the code from http://wpshout.com/wordpress-submit-posts-from-frontend/ , but it doesn’t  handle file attachment, indeed most people and I was demand on image uploads for status update,  photo blogging.. whatever . But to get working with build-in WordPress media upload function require a lots of code work,  and if you prefer a fully functional media library, you could base on P2 theme instead.

    How it work

    1. It create a post form to allow  the post content inserted by wp_insert_post.
    2. following the post_id, it attach the uploaded files to the post.
    3. Set the first ordered image to the post “featured images”
    4. Lastly, you call get_all_thumbnails before the_content() in order to retrieve the uploaded files.

    Limitation

    The critical limitation is lack of media features, unlike build-in media library, you can customize your post images and place it on your desired position. Therefore the images only able to retrieve by the_post_thumbnail() for single image or get_all_thumbnails() for multiple images.

    (More …)

     
  • levin 1:31 am on June 7, 2010 Permalink | Reply
    Tags: , wordpress   

    WordPress post navigation with customized post loop using meta_key 

    What’s that?

    I wrote this stupid navigation workout because I can’t found any of good practice on writing customized content unless I go for WordPress 3.0. When I create several content handling in a themes, such as photo post or video post, I was relied on the meta_key value to determine which style to be used.

    For each single post or post loop, it’s no problem at all, however when i tried to do navigation on the single.php. I noticed that there is no way to treat them as typical blog post.

    <?php
            $category = get_the_category();
            $catID = $category[0]->cat_ID;
    ?>
    
        <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content();?>
            <?php endwhile; else: ?>
    <p>Sorry, no posts matched your criteria.</p>
            <?php endif; ?>
    
    <!-- Start navigation here -->
    <?php
    global $post;
    $mypostlist = array();
    $currentPID = $post->ID;
    $myNav[] += $currentPID;  //insert the current post into first array position
    $myposts = get_posts('exclude='.$post->ID.'&orderby=date&order=desc&numberposts=-1&meta_key=my_post_type&meta_value=1&offset=1&category='. $catID .'');
    setup_postdata($post); // exclude current post from the loop
    foreach ($myposts as $post) {
           $myNav[] += $post->ID; // insert the result into the loop
    }
    $current = array_search($post->ID, $myNav);
    $prevID = $myNav[$current-1];
    $nextID = $myNav[$current++];
    ?>
    
    <div class="navigation">
    <?php if (!empty($prevID)) { ?>
    <div class="alignleft"><a href="<?php echo get_permalink($prevID); ?>"
      title="<?php echo get_the_title($prevID); ?>">Previous</a>
    </div>
    <?php }
    if (!empty($nextID)) { ?>
    <div class="alignright"><a href="<?php echo get_permalink($nextID); ?>"
     title="<?php echo get_the_title($nextID); ?>">Next</a></div>
    <?php } ?>
    </div><!-- .navigation -->
    
    </div>
    
    
     
  • levin 4:06 am on February 25, 2010 Permalink | Reply
    Tags: , , , performance, , wordpress   

    Performance tuning on Apache, PHP, MySQL, WordPress v1.1 – Updated 

    Introduction

    This tutorial is covering the web server performance tunings on MySQL, PHP and Apache, WordPress and BuddyPress or general web hosting purpose, the tuning example is based on CentOS 5.

    The key of the following performance tuning is focus on memory and caching, most of people host a web site or forum or blog without any tunings or even use the all out-of-box setting.

    (More …)

     
    • Chris 10:41 am on August 27, 2010 Permalink | Reply

      Thank for performa tuning server guide.

    • Eric Nielsen 7:31 am on January 21, 2011 Permalink | Reply

      Followed your instructions to setup FastCGI, all worked well accept at the end, when I hit my website, I get:

      #!/bin/bash
      PHP_CGI=/usr/bin/php-cgi
      PHP_FCGI_CHILDREN=16
      PHP_FCGI_MAX_REQUESTS=1000
      export PHP_FCGI_CHILDREN
      export PHP_FCGI_MAX_REQUESTS
      exec $PHP_CGI

      • levin 1:59 pm on January 21, 2011 Permalink | Reply

        Hi, please make sure you have the similar lines as below.

        ScriptAlias /cgi-bin/ “/var/www/cgi-bin/”

        \< Directory "/var/www/cgi-bin" \>
        AllowOverride None
        Options None
        Order allow,deny
        Allow from all
        \< \/Directory \>

  • levin 1:11 pm on December 18, 2009 Permalink | Reply
    Tags: wordpress   

    WordPress post template for theme testing. 

    A very useful html element template used for theme testing.

    WordPress  theme test template

     
  • levin 1:04 pm on December 18, 2009 Permalink | Reply
    Tags: wordpress   

    WordPress Howto retrieve top parent category ID from the post 

    Add the following code in your theme functions.php

    function is_parent_category($cats, $_post = null)
    {
    	foreach ((array) $cats as $cat)
    	{
    		$descendants = get_term_children((int) $cat, "category");
    		if ($descendants && in_category($descendants, $_post))
    			return true;
    	}
    	return false;
    }
    
    ?>
    
    
    Usage:
    if (is_parent_category(1)) // Got true/false if parent category is 1
    {
    //Do something
    }
    
     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel