2012-10-24 60 views
0

我有一個PHP while循環如下:PHP循環沒有被應用特定HTML元素

<?php while (have_posts()) : the_post(); ?> 

<li> 
<?php 
    $args = array(
     'post_type' => 'attachment', 
     'numberposts' => -1, 
     'post_status' => null, 
     'post_parent' => $post->ID, 
     'orderby' => 'menu_order', 
     'order' => 'ASC' 
    ); 

    $attachments = get_posts($args); 

    if ($attachments) { 
     foreach ($attachments as $attachment) { 
     $image_attributes = wp_get_attachment_image_src($attachment->ID, large); 
     $alt_text_title = $attachment->post_title ; 
     //print_r($attachment); 

     echo "<img src=\"$image_attributes[0]\" alt=\"$alt_text_title\">"; 
     } 
    } 
?> 
<h3><a href="http://<?php the_title(); ?>"><?php the_title(); ?></a></h3> 
<?php the_content(); ?> 
</li> 
<?php endwhile;?> 

的的H3內部的標籤,使所有的標題鏈接,但是我想這些標題的一個不一個鏈接因此不會受到a標籤的影響..

這可能嗎?

+0

什麼the_title()?你在使用某種框架嗎? – Toping

+1

這是一個wordpress主題。 –

+0

wordpress for the portfoio ... the_title()正在爲相關項目添加插入的標題。 – Alex

回答

1

編輯。一種更安全的方式,通過郵政編號來完成。

<?php $postID = $post->ID; 

echo $postID; 
// You could delete this line once you have the PostID. 

if($postID == '1') { ?> 
    <h3><?the_title();?></h3> 
<?php } else { ?> 
    <h3><a href="<?php the_permalink();?>" title="<?php the_title();?>"><?the_title();?></a></h3> 
<?php } ?> 
+3

這將改變所有的H3元素。他只想改變一個。 – Dpolehonski

+0

編輯爲不輸出基於PostID的''。 – SMacFadyen

0

你可以經常檢查the_title()有如果內容,僅在需要時顯示的標籤。

<?php if(the_title() === "your title") {?> 
    <h3><?php the_title(); ?></h3> 
<?php } else {?> 
    <h3><a href="http://<?php the_title(); ?>"><?php the_title(); ?></a></h3> 
<?php } ?> 
+0

的事情是,內容將永遠插入在該領域,使條件永遠是真實的。 – Alex

+0

對不起,但後來我真的不明白。沒有一個您不想顯示爲超鏈接的特定標題?難道你不能用這個特定的標題取代「你的標題」嗎?不管怎樣,硬編碼的字符串都不會改變。 (或者你是否想告訴我,the_title()總是包含相同的字符串?當然,這是另一回事)) –

+0

標題匹配真正的超鏈接,但其中一個是因爲某些原因不生活,所以我不想要標題顯示周圍的標籤....很抱歉,如果它有點混亂... – Alex

0
$title=get_the_title(); 
if(/*post meets some condition*/) { 
    ?><h3>$title</h3><?php 
} else { 
    ?><h3><a href="http://<?php the_title(); ?>"><?php the_title(); ?></a></h3><?php 
} 
0

你只需要一個簡單的if語句。您可以在例如生病使用任意數量的事物建立條件的全稱,但它可能會更好使用後或類似的東西的ID:

<?php if('Ignore this title' == get_the_title()): ?> 
    <h3><?php the_title() ?></h3> 
<?php else: ?> 
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3> 
<?php endif; ?>