2011-06-08 53 views
2

基本上,我想這一點:僅當頁面區域中的編號不同時才執行代碼?

The highest voted 

answer 3 vote 

The others 

answer 1 vote 
answer 2 vote 
answer 1 vote 

但我想避免這種情況:

The highest voted 

answer 3 vote 

The others 

answer 3 vote 
answer 3 vote 
answer 1 vote 

這是沒有意義的,因爲有其他的答案如下投3中。

所以我想創建一個if else語句是這樣的:

(run this only if there isn't posts with the same amount of votes) 

The highest voted 

answer 3 vote 

(end if) 

The others 

answer 3 vote 
answer 3 vote 
answer 1 vote 
在這種情況下的代碼(收視率最高的答案)不應該運行

如此。

我不確定是否應該使用php或jQuery。

The_votes();函數輸出如下:+2 votes所以我不能直接使用它,因爲它有文本。

我可以根據divs或div類進行比較。

有關如何編碼的任何建議?

編輯:

每個答案的PHP和HTML內容的例子:

<h2><?php the_title(); ?></h2> 
     <?php the_content(); ?> 
     <?php bbp_reply_admin_links(); ?> 
     <h4><?php bbp_topic_reply_count(); ?></h4> 
     <div class="topic-like-count"> 
    <?php if(function_exists('the_votes')) { the_votes(); } ?> 

我想我只有得到the_votes數量,做一些事情。

回答

1

爲什麼不能使用voting();

即使返回文本就像+xx votes;你可以retrive編號爲:

$voting = voting(); 
$votes = substr($voting,1,strpos($voting,' ')-1); 
+0

感謝我不是很熟悉PHP。之後,我該怎麼辦? – alexchenco 2011-06-08 14:43:28

+0

我沒有得到你需要的輸出。發佈一個html例子 – dynamic 2011-06-08 14:44:50

相關問題