2015-04-23 12 views
2

我有一個PHP elseif的代碼看起來像,的Joomla 3,改變PHP否則,如果爲站點鏈接到一些全球

 <?php if ($item->getPrimaryImage()) :?> 
     <img src="<?php echo $item->getPrimaryImage()->getSource(); ?>" class="sprocket-lists-image" alt="" /> 
     <?php endif; ?> 
     <?php echo $item->getText(); ?> 
     <?php if ($item->getPrimaryLink()) : ?></br> 

     <?php if ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=3200") : ?></br> 
     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a> 

     <?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=1508") : ?></br>    
     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a> 

     <?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=1840") : ?></br>    
     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a> 

     <?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=2541") : ?></br>    
     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a>  

     <?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/topmenu-1478/3350-2015-03-10-09-52-10") : ?></br>    
     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a>  

     <?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=3426") : ?></br>    
     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a>  

     <?php elseif ($item->getPrimaryLink()->getUrl() == "index.php/component/content/article?id=3420") : ?></br>    
     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a>     

     <?php else : ?></br> 

     <a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="modal" rel="{size: {x: 1024, y: 550}, handler:'iframe'}"><span><?php rc_e('READ_MORE'); ?></span></a>  

     <?php endif; ?> 
     <?php endif; ?> 

的代碼非常簡單,那就是

  1. 所有elseif有一個鏈接開始像==「index.php ...等,,,這意味着讀取按鈕將打開像_parent鏈接沒有MODAL ..

  2. 最後(案件)其他打開所有其餘的林KS裏面的MODAL

問題

你會發現,像開始「的index.php/.. ,,, 是有編碼,以避免所有的任何方式都在elseif的情況下,鏈接elseif和全球化,這意味着將認識到起始鏈接「index.php/..? 你會發現,在隨後的行動在所有的情況下,ELSEIF

<a href="<?php echo $item->getPrimaryLink()->getUrl(); ?>" class="readon"><span><?php rc_e('READ_MORE'); ?></span></a> 

是一樣的。

我需要一段代碼,就明白了,認識的鏈接開始「的index.php/.. 這可能嗎?

目標

我的目標是,我不想用這麼許多elseif每次必須添加一個新的鏈接,代碼會照顧它,現在每當我必須添加一個新的圖像橫幅,將鏈接到joomla網站內的文章,我必須硬編碼並添加一個新的elseif像上面,,否則它會打開它的模態..

我希望其明確的eno唉,請一些幫助的原因我嘗試的年齡來解決這個..

預先感謝您閱讀這篇..

回答

0

一般如果子句來檢查,如果一個字符串與特定的單詞開始是:

<?php if(substr($item->getPrimaryLink()->getUrl(), 0, 10) == "index.php/") : ?> 
... 
<?php endif; ?> 

參考:substr

+0

伊曼紐爾你治!這是eaxclty,我正在尋找,substr工作像一個魅力, – dc03kks

+0

標記爲正確的答案!! ,,非常感謝你的努力 – dc03kks

+0

聽到這一點很高興,歡迎你! – emmanuel

0

使用的URL庫像http://url.thephpleague.com/3.0/應該做的工作之間爆發的網址:

index.php/component/content/article

和GET參數ID。

然後你可以簡化你的代碼。

相關問題