GG資源網

截斷WordPress上的日期對象

問題描述:

When my website shows a snippet of a blog post through any widget, it displays the featured image, the title, the first characters of the text itself and the date the post was made.

Inside WordPress\' content.php, it shows the date using the_time(), like this:

The parameter \'M\' passed in the function the_time() is supposed to give PHP the month written with only 3 characters (January would be JAN, February would be FEB and so on).
In my native language (which is portuguese) it gets the months, obviously, in portuguese: January is Janeiro, February is Fevereiro... which doesn\'t matter for the_time(\'M\'), it truncates it the same way.

My problem is that the month May is Maio in portuguese, a 4-letter month. Upon passing it to PHP, for some obscure reason, it doesn\'t get truncated. It keeps it Maio, which obviously prejudices my layout.
I\'m not a PHP developer, but I did a little research and tried a workaround inside the content.php, but it doesn\'t work:

It might even be syntax issues, because I really don\'t know PHP, but it seems that I might need it to solve this problem. Am I going the right way here? I appreciate any help you give me!

TL;DR: I need to truncate a 4-letter date into a 3-letter one and pass it back to HTML.

圖片轉代碼服務由CSDN問答提供

感謝您的意見,我們儘快改進~
功能建議

當我的網站通過任何小部件顯示博客帖子的片段時,它會顯示特色圖片,標題, 文本本身的第一個字元和帖子的日期</ em>。</ p>

在Wordpress的content.php中,它使用 the_time()顯示日期 </ em>,像這樣:</ p>

 &lt; div class =「date-box」&gt;
&lt; div class =「day」&gt;&lt;?php the_time(\'d\'); ?&gt;&lt; / div&gt;
&lt; div class =「month」&gt;&lt;?php the_time(\'M\'); ?&gt;&lt; / div&gt;
&lt; / div&gt;
</ code> </ pre>

函數the_time()中傳遞的參數\'M\'應該為PHP提供月份 只寫3個字元(1月份是1月,2月份是FEB等等)。
用我的母語(葡萄牙語),很明顯,用葡萄牙語來表示幾個月:1月是 Janeiro </ em> ,二月是 Fevereiro </ em> ...這對於 the_time(\'M\')</ em>無關緊要,它會以同樣的方式截斷它。</ p>
我的問題是 五月份的葡萄牙語是 Maio </ em>,一個4個字母的月份。 在將其傳遞給PHP時,由於某些不明原因,它不會被截斷</ em>。 它保留了 Maio </ em>,顯然會損害我的布局。
我不是PHP開發人員,但我做了一些研究並在content.php中嘗試了一種解決方法,但它不起作用:

 <  code>&lt; div class =「month」&gt;
&lt;?php
$ t = the_time(\'M\');
if(strlen($ t)&gt; 3){
echo mb_strimwidth($ t ,0,3);
} else {
echo $ t;
};
?&gt;&lt; / div&gt;
</ code> </ pre>

它可能 甚至是語法問題,因為我真的不懂PHP,但似乎我可能需要它來解決這個問題。 我在這裡走的是正確的嗎? 感謝你給我的任何幫助!</ p>

TL; DR:我需要將4個字母的日期截斷為3個字母的日期並將其傳回HTML。</ p> \\ n </ div>

網友觀點:

WordPress\' the_*() functions all echo their output directly and don\'t return anything, so you can\'t assign the value to a variable. You\'re looking for get_the_time().

The rest of your code looks like it should work just fine.

由於網站搬家,部分鏈接失效,如無法下載,請聯繫站長!謝謝支持!
1. 帶 [親測] 說明源碼已經被站長親測過!
2. 下載後的源碼請在24小時內刪除,僅供學慣用途!
3. 分享目的僅供大家學習和交流,請不要用於商業用途!
4. 本站資源售價只是贊助,收取費用僅維持本站的日常運營所需!
5. 本站所有資源來源於站長上傳和網路,如有侵權請郵件聯繫站長!
6. 沒帶 [親測] 代表站長時間緊促,站長會保持每天更新 [親測] 源碼 !
7. 盜版ripro用戶購買ripro美化無擔保,若設置不成功/不生效我們不支持退款!
8. 本站提供的源碼、模板、插件等等其他資源,都不包含技術服務請大家諒解!
9. 如果你也有好源碼或者教程,可以到審核區發布,分享有金幣獎勵和額外收入!
10.如果您購買了某個產品,而我們還沒來得及更新,請聯繫站長或留言催更,謝謝理解 !
GG資源網 » 截斷WordPress上的日期對象

發表回復

CAPTCHAis initialing...
© 2021-GG資源網 - www.ggplus.cn. All rights reserved