我正在爲新聞顯示創建一個模塊。我想知道是否有更好的方式來顯示我的文章的信息。我希望能夠以不同的方式顯示信息部分,並具有開/關功能。例如:以不同方式顯示字符串
- 標題
- 文本
- Readmore
- 日期
- 作者
或只是
- Readmore
- 標題
我在考慮這段代碼,但我相信有更好的解決方案嗎?
<div id="pos1">
<?php
if (show = 1) {
echo 'Here will be title';
elseif (show = 2) {
echo 'Here will be text';
elseif (show = 3) {
echo 'Here will be readmore';
.....
else { $string = 'nothing here'; }
?></div>
<div id="pos2">
<?php
if (showsecond = 1) {
echo 'Here will be title';
elseif (showsecond = 2) {
echo 'Here will be text';
elseif (showsecond = 3) {
echo 'Here will be readmore';
.....
else { $string = 'nothing here'; }
?></div>
是'表演,showsecond'變量?它們來自 – safarov 2012-04-09 06:30:14
是的,它是一個變量 – sdfgsdfg 2012-04-09 06:36:17
'show'和'showsecond'不是有效變量,php會將它們解釋爲文字字符串'show'和'showsecond'所有變量都必須以「$」作爲前綴 – nathanjosiah 2012-04-09 06:38:41