Posted on 2010 under Blogger |
7
Apr
If you want to add related posts to a single post, you can use the following codes:
<?php
//for use in the loop, list 5 post titles related to first tag on current post
$tags = wp_get_post_tags($post->ID);
if ($tags) {
echo ‘Related Posts’;
$first_tag = $tags[0]->term_id;
$args=array(
‘tag__in’ => array($first_tag),
‘post__not_in’ => array($post->ID),
’showposts’=>5,
‘caller_get_posts’=>1
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post(); ?>
<p><a href=”<?php the_permalink() ?>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></a></p>
<?php
endwhile;
}
}
?>
Just insert the code to your wordpress theme single.php,then you will get the related posts displayed within every single post.
Hello,recently,I am learning fireworks to make different kinds of image,above is one image made by myself,please put your comments,and if you have any other ways to make nice looking images,please feel free to share your information here.
If possible I will post the way to reach image like above in my next post.
Posted on 2009 under Uncategorized |
21
Mar
Foreach (array_expression as $value){
statement;
}
Foreach (array_expression as $key => $value){
statement;
}
for example
<?php
$arr = array(2,3,4,5) ;
foreach($arr as &$value){
$value = $value * 2;
}
//$arr now is array(4,6,8,10)
unset($value);//break the reference with the last element
//warning Reference of a $value and the last array element remain even after the foreach loop.It is recommended to destroy it by unset().
?>
<?php
$arr = array(”apply “,”orange”,”banana”);
reset($arr); //Set the internal pointer of an array to its first element
foreach($arr as $key => $value){
echo “Key:$key;Value:$value<br />\n”;
}
?>
Posted on 2009 under Design Your Site, Web Page Design |
20
Mar
In case you have lots of articles need to be show within the homepage,however,if we show all the links within homepage,that will make the homepage really ugly,how can we keep the links while make our site good looking.
We can use this script as follows:
<script language=JavaScript>
<! –
function MAP(s)
{var d = s.options[s.selectedIndex].value;
open(d,”open”);
s.selectedIndex=0 ;
}
//–>
</script>
<form name=milHomeLink>
<select onchange=”MAP(this);” size=”1″ selze=”1″ name=”select2″>
<option>Please choose your article</option>
<option value=”http://www.yoururlone.com”>yourtitleone</option>
<option value=”http://www.yoururltwo.com”>yourtitletwo</option>
<option value=”http://www.yoururlonethree.com”>yourtitlethree</option>
<option value=”http://www.yoururlonefour.com”>yourtitlefour</option>
<option value=”http://www.yoururlonefive.com”>yourtitlefive</option>
</select>
</form>
Quite easy right,in fact,it is very useful.
Hope this can help you to get save space for you pages.
Posted on 2009 under PHP |
14
Jan
Hello guys,the email() function in php could be very useful to send emails.If we could use php to create email address and then we can use email() function to send mails to others.
Okay,here I just write some code,if you needed,you can use them.
You can create a file let’s say email.php and save all the code within the file.
<?php header(”Content-Type:text/html;charset=utf-8″); ?>
<?php
$s = 1000;////////////////$s stand for how many emails you want to create,I set it as 1000.
for($i = 1;$i <= $s;$i++){
$qqemail9 = rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . “@qq.com”;
$qqemail8 = rand(1,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . rand(0,9) . “@qq.com”;
$num = rand(1,2);
if($num = 1){
$to = “{$qqemail9}”;
$subject = “this is the subject”; //////////////////sent “this is the subject” with your subject.
$message = “this is the content” . ” \r\n “; //////////////////sent “this is the content” with your content.
echo $i . ” ” . $to . “<br />”;
mail($to, $subject, $message, “FROM: sender@sender.com”);////////sender@sender.com is your own address,you can change it to your own email address.
}elseif($num =2){
$to = “{$qqemail8}”;
$subject = “this is the subject”; //////////////////sent “this is the subject” with your subject.
$message = “this is the content” . ” \r\n “;//////////////////sent “this is the content” with your content.
echo $i . $to . “<br />”;
mail($to, $subject, $message, “FROM: sender@sender.com”);////////sender@sender.com is your own address,you can change it to your own email address.
}
}
echo “You have sent” . $s . “emails”;
?>
Just upload the email file to your hosting and open the file you will have 1000 emails sent.