您好,我正在嘗試針對特定帖子進行分類以顯示在特定頁面上。WordPress針對特定頁面上的特定帖子類別
我建立一個住房建築商的網站,所以我必須交的類別,如
1)房屋出售 2)顯示舍 3)特點的家園 4)可用批次
,我有網頁核心反應到類別。 1)顯示舍2)可用公寓3)可用批次
我試圖做到的是,我要顯示這樣
組合在頁(適用HOMES) - 所有帖子說的是分類/蛞蝓 「出售公寓」
在頁面(SHOW HOMES) - 所有帖子說的是分類/蛞蝓 「展家」
我不知道如何做到這一點....
這是我得到了多少:
<?php if(have_posts()):?>
<?php while(have_posts()) : the_post();
$categoris = get_the_category();
print_r($categoris);
if($categories){
$class_names = array();
foreach($categories as $category){
$class_names[] = $category->slug;
}
$classes = join(' ', $class_names);
}
?>
<div class="row">
<div class="large-4 columns">
<div class="panel bodyHeight">
<?php if(has_post_thumbnail()) : ?>
<a href="<?php the_permalink();?>"><?php the_post_thumbnail(); ?></a>
<?php endif;?>
</div>
</div>
<div class="large-8 columns">
<div class="panel bodyHeight">
<p>Price:
<?php $custom_fields = get_post_custom();
$price = $custom_fields['price'];
foreach($price as $key => $value){
echo $value;
}
?>
</p>
<p>SqF:
<?php $custom_fields = get_post_custom();
$sqf = $custom_fields['sqf'];
foreach($sqf as $key => $value){
echo $value;
}
?>
</p>
<p>Number of Bedrooms:
<?php $custom_fields = get_post_custom();
$bed = $custom_fields['num_bedrooms'];
foreach($bed as $key => $value){
echo $value;
}
?>
</p>
<p>Number of Bathrooms:
<?php $custom_fields = get_post_custom();
$bath = $custom_fields['num_bathrooms'];
foreach($bath as $key => $value){
echo $value;
}
?>
</p>
<p>Home Description:
<?php $custom_fields = get_post_custom();
$desc = $custom_fields['description'];
foreach($desc as $key => $value){
echo $value;
}
?>
</p>
<p>Home Location:
<?php $custom_fields = get_post_custom();
$address = $custom_fields['address'];
foreach($address as $key => $value){
echo $value;
}
?>
</p>
</div>
</div>
</div>
<?php endwhile;?>
<?php else: ?>
<div class="row">
<div class="large-4 columns">
<div class="panel bodyHeight">
<h3>No posts were found.</h3>
</div>
</div>
</div> <?php endif;?>
</div>
謝謝,我已閱讀第二個鏈接,但我處於主要時間線下,無法及時學習自定義類型。目前,我擁有我需要正確工作的一切,我需要的僅僅是學習如何按類別(過濾)當前帖子。 我現在所做的是爲每個頁面創建單獨的頁面,因此我有page-show-home.php並且我有頁面'Show Home'使用該頁面作爲模板。我現在需要的是一個由slug/category – Ljubisa
的過濾器啊,所以我有點不清楚。每個頁面都會知道這個slu,,你只需要從這個slu category的類別中獲得帖子。那是對的嗎? –
也要明白你的slu will不會是「單詞」,他們會成爲「單詞」。「word word」將是名字 –