Tagged: php Toggle Comment Threads | Keyboard Shortcuts

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

    Submitting WordPress post from frontend without a plugin 

    Screen Shot

    Screen Shot


    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/.


    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.


    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: php,   

    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.

            $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 -->
    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>
    <?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 -->
  • levin 1:31 am on May 28, 2010 Permalink | Reply
    Tags: php   

    PHP sample: howto distinct the subarray value 

    The Code

    $myvars = array(
    "myvar1" => array("stock" => "C", "mykey" => "1", "name" => "apple"),
    "myvar2" => array("stock" => "D", "mykey" => "1", "name" => "apple"),
    "myvar3" => array("stock" => "E", "mykey" => "1", "name" => "apple"),
    "myvar4" => array("stock" => "F", "mykey" => "1", "name" => "apple"),
    "myvar5" => array("stock" => "G", "mykey" => "2", "name" => "orange"),
    "myvar6" => array("stock" => "H", "mykey" => "2", "name" => "orange"),
    "myvar7" => array("stock" => "I", "mykey" => "2", "name" => "orange"),
    "myvar8" => array("stock" => "J", "mykey" => "2", "name" => "orange"),
    $_myvars = array();
    foreach($myvars as $myvar)
    if ( !in_array($myvar['mykey'], $_myvars) )
    echo $myvar['mykey'] . "\n" . $myvar['name'] . "\n";  
    $_myvars[] = $myvar['mykey'];

    The Result

    1 apple 2 orange
  • levin 4:06 am on February 25, 2010 Permalink | Reply
    Tags: , , , performance, php,   

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


    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:

      export PHP_FCGI_CHILDREN
      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 7:49 pm on March 27, 2009 Permalink | Reply
    Tags: horde, php   

    horde/imp display gb2312 character interim solution 

    While too many gb2312 character in horde cannot converted as UTF-8, to give it a quick workaround, I’d just enforce horde to treat gb2312 encoding to gbk which is more compatible for chinese double-byte character.

    Replace the lines in lib/Horde/String.php from

    if (!$output && String::extensionExists(‘mbstring’)) {
    $output = @mb_convert_encoding($input , $to, $from);


    if (!$output && String::extensionExists(‘mbstring’)) {
    if ($from == ‘gb2312′) {
    $from = ‘GBK,GB2312′;
    $output = @mb_convert_encoding($input , $to, $from);

compose new post
next post/next comment
previous post/previous comment
show/hide comments
go to top
go to login
show/hide help
shift + esc