2014-01-09 97 views
0

我有不同用戶的帖子,我創建了一個名爲「offers」的custom_post_type。當用戶在wordpress登錄時只能看到他自己的帖子和優惠。關聯自定義帖子類型與帖子或用戶

是否有可能提議與用戶關聯後(用戶只能創建一個職位

的問題是:我可以顯示的index.php文件後和archive.php圖標時後的用戶有「優惠」

+0

其實,你試圖達到的目標有點駭人聽聞,但我認爲你可以,如果你給予不同的使用能力rs和關聯功能與能夠查看菜單項並編輯這些項目,看看:http://codex.wordpress.org/Roles_and_Capabilities –

+0

謝謝@LouisXIV我有這種能力。用戶只能看到他自己的報價和條目。問題是,如果用戶有優惠,我想在index.php(帖子)中顯示優惠圖標。一些想法? – vektor

+0

@LouisXIV我改進了這個問題(我認爲:)) – vektor

回答

0

你似乎想做一個循環,一個循環,我不知道這是否是最有效的方式做到這一點,但我想它會工作:??

<?php 
// First loop 
while (have_posts()): the_post(); 
$author_id = get_query_var('author'); 
    $offers = array(); 

    // Second Loop 
    $i = 0; 
    $args = array(
     'author' => $author_id, 
     'post_type' => 'offers' 
    ); 
    $the_query = new WP_Query($args); 
    if ($the_query->have_posts()) : 
     while ($the_query->have_posts()) : $the_query->the_post(); // check if it has offers, if it has, loop over the offers 
      $offers[$i]['title'] = get_the_title(); // or anything you need 
      $i++; 
     endwhile; // close the loop 
    else: // if it has no post 
     continue; // we don't display the post 
    endif; 

    wp_reset_postdata(); 
    ?> 
<div class="post"> 
<?php 
the_title(); // or anything you need 

foreach ($offers as $offer): 
    echo $offer['title']; // we display the title of the offer 
endforeach; 
?> 
</div> 
<?php endwhile; ?> 
+0

但是這個代碼是index.php例如?我想要一個「如果」。如果用戶有「offer」,在index.php上顯示帶有鏈接的圖標(用戶的帖子) – vektor

+0

我更新了我的答案以嘗試適合您的需求,因爲它非常具體... –

+0

Im測試但代碼有錯誤這裏:<?php wp_reset_postdata(); ?>也許是因爲第一個<?php沒有關閉? – vektor

相關問題