2011-05-28 64 views
1

我想刪除Google搜索顯示的元日期。我碰到這個代碼通常在single.php中發現來到使用javascript顯示php時間/日期函數的幫助

<?php the_time(‘M j, Y’);?> 

需要重新寫爲:

<script language=」javascript」 type=」text/javascript」> document.write(‘<?php the_time(‘j’) ?>’); </script> <?php the_time(‘M Y’) ?> 

但是我single.php中使用這種格式

<?php the_time(get_option('date_format')); ?> 

哪有我使用JavaScript的上述代碼?

+0

the_time?從來沒有見過這個,是你自己的功能還是你的框架? – Ibu 2011-05-28 05:40:36

+1

只需使用'date('j')'; – Ibu 2011-05-28 05:41:16

回答

0
<script language=」javascript」 type=」text/javascript」> document.write(‘<?php the_time(get_option("date_format")); ?>’);</script> 

這將隱藏整個日期,而不僅僅是一個月的日期。 (這是你想要的嗎?)

+0

這是它給出的錯誤:解析錯誤:語法錯誤,意外的';' – Sledge81 2011-05-28 06:10:07

+0

@Trott:你忘了'echo'the_time' funciton ... :) – 2011-05-28 06:15:30

+0

那麼它會以這種格式呢? document.write('<?php echo'the_time(get_option(「date_format」)''>') – Sledge81 2011-05-28 06:16:56

0

儘管一個班輪可以工作,但是這樣寫的代碼會導致代碼混亂。你的代碼應該閱讀並且易於閱讀,就像一本書一樣。

<?php 
// the date() object should be used for this, and the following would normally by 
// shoved in a function. 

$date['j'] = the_time('j',get_option('date_format')); 
$date['M'] = the_time('M', get_option('date_format')); 
$date['Y'] = the_time('Y', get_option('date_format')); 
// Build the date string the way want it 
$date['full'] = "Today, the " . $date['j'] . "of " . $date['M'] . ", " . $date['Y']; 
?> 

<script language="javascript" type="text/javascript">document.write('<?php echo date["full"]; ?>');</script>