Tuesday, June 29, 2010

Display 5 latest posts in each category in WordPress

<div id="page-not-found" class="post-page">

<?php
$cat_args = array(
'orderby' => 'name',
'order' => 'ASC',
'child_of' => 0
);

$categories = get_categories($cat_args);

foreach($categories as $category) {
echo '<dl>';
echo '<dt> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>' . $category->name.'</a></dt>';

$post_args = array(
'numberposts' => 5,
'category' => $category->term_id
);

$posts = get_posts($post_args);

foreach($posts as $post) {
?>
<dd><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></dd>
}
echo '<dd class="view-all"> <a href="' . get_category_link( $category->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $category->name ) . '" ' . '>View all posts in ' . $category->name.'</a></dd>';
echo '</dl>';
}
?>
<div class="page-end"></div>

</div>



CSS

#page-not-found dl {
width: 200px;
float: left;
padding: 0 18px 0 0;
height: 250px;
}

#page-not-found dt {
font-weight: bold;
font-size: 1.1em;
padding: 10px 0;
}

#page-not-found dt a {
color: #b0bf32;
}

#page-not-found dd.view-all {
border-top: 1px solid #c9c9c9;
font-size: 0.9em;
margin: 5px 0;
padding: 2px 0 0;
text-align: right;
}

#page-not-found dd.view-all a {
color: #999;
}

.page-end {
clear: both;
}

display the_content with setup_postdata

<?php

global $more;

$cat= 3;
$posts = get_posts ("cat=$cat&showposts=5");
if ($posts) {
foreach ($posts as $post):
$more = false;
setup_postdata($post);
?>
<h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
<p class="storycontent"><?php the_content('Read more...'); ?></p>
<?php
endforeach;
$more = true;
}

?>

Monday, June 28, 2010

Show future posts on single post

today i show how to display future posts in single.php. you just copy code below into funciton.php.

add_filter('the_posts', 'show_future_posts');

function show_future_posts($posts)
{
global $wp_query, $wpdb;

if(is_single() && $wp_query->post_count == 0)
{
$posts = $wpdb->get_results($wp_query->request);
}

return $posts;
}

Displaying Future Posts in WordPress

If you do like I do and schedule posts ahead of time (especially on the podcast), there’s a way inside of WordPress to show your readers what posts are coming up next:

<?php
$my_query = new WP_Query('post_status=future&order=DESC&showposts=5');
if ($my_query->have_posts()) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<?php the_date(); ?> - <?php the_title(); ?>
<?php endwhile;
}
?>


This will display up to 5 “scheduled” posts wherever you drop in the code. Add a headline <h2> tag if you want to give it a title (should you want to use it as a widget).

Want to see this code in action? Check the WordPulse podcast page‘s sidebar to see it working!

Display a List of Upcoming Posts in WordPress

When you have completed a post in WordPress, you have the ability to save it as a draft, publish it immediately or schedule a future date when it will be published automatically.

This is extremely helpful if you want to plan ahead or if you use your WP site for events. Creating a simple list of upcoming posts lets your visitors know what they can look forward to and is pretty simple to do.




The following code can be placed in your sidebar on within any
template.
<?php
$futurePosts = new WP_Query();
$futurePosts->query('showposts=5&post_status=future&order=ASC');

if ($futurePosts->have_posts()) : while ($futurePosts->have_posts()) :
?>
<ul>
<li><?php the_title(); ?><br /><small><?php the_time(get_option('date_format'); ?></small></li>
</ul>
<?php endwhile; else: ?>
<ul>
<li>No upcoming events.</li>
</ul>
<?php endif; ?>

If you want to only display future posts from a specific category, you

$futurePosts->query('showposts=5&post_status=future&order=ASC&cat=12');

can add a cat=$id to the query like so:

Sunday, June 13, 2010

unknow error occurred (0xE8008001)

today i show you how to fixed unknow error occurred (0xE8008001) when you jailbreak ipod

http://thy4u.blogspot.com/2010/06/how-to-jailbreak-your-iphone-with.html

Thursday, June 10, 2010

How to jailbreak your Ipod with BlackRa1n RC3

Step 1: Update iTunes to the latest version available and reboot your computer.

Step 2: Download BlackRa1n RC3 from our iPhone downloads page and install it, then reboot your computer.

Step 3: Plug your iPhone in your computer and launch BlackRa1n RC3. Click on "make it ra1n"



Step 4: Your iPhone will enter recovery mode. The regular recovery mode image on your iPhone will be replaced by a picture of GeoHot (same as image above).



Step 5: BlackRa1n will run on your iPhone and then it will reboot.



A pop up will show up asking you to donate. If you successfully jailbreak your iPhone, I suggest you send $5 or $10 to GeoHot.



Step 6: Once your iPhone reboots, you will have a new icon on your springboard. This is BlackRa1n. Now make sure you have internet connection and launch BlackRa1n on your iPhone.



Step 7: Choose what installer applications you want to install on your iPhone and then tap “Install”. I suggest only installing Cydia but you may install them all if you want to.



BlackRa1n will download and install the selected applications.

Step 8: Once done installing, your iPhone will respring and you should see your installer app on your springboard.




Step 9: Once your installer app (Cydia in our case) is installed. You can safely uninstall BlackRa1n by launching the app and selecting “uninstall balckra1n”.



Step 10: Reboot your iPhone. You’re done!

Step 11: install appsync from http://www.sinfuliphonerepo.com

Goto: Cydia > Manage > Sources > Edit > Add



Hopefully this jailbreak will go more smoothly than with BlackRa1n RC3. If you have any question or comment, please leave a comment below.

Tuesday, June 8, 2010

String Search & Replace (AS2 & AS3)


function strReplace($str:String, $search:String, $replace:String):String
{
return $str.split($search).join($replace);
}
var str:String = new String();
str = "we are Khmer!"
trace(strReplace(str,"we","We"));

The "split" function splits the string at the word ($search) you're searching for. And the "join" inserts the new word ($replace) between the elements, concatenates them, and returns the resulting string