我建立一個主題,我category.php頁面上的其餘部分我想展示幾個全員額(假設3,但需要能夠改變這到2或1很容易),然後其餘的職位類別作爲標題鏈接。顯示catgegory頁面上三個完整的帖子,再上崗的僅標題
我有相當多的HTML在我環路造型我的職位,加入所有的代碼很抱歉自定義字段,但是這是我的category.php頁面的樣子了。我已經嘗試了一些沒有工作的東西,所以編輯了這個來顯示我的原始代碼,它只是有一個正常的職位列表。我對編輯The Loop有所不同,因此會盡可能多地解釋/澄清。
<?php
/**
* The template for displaying Category Archive pages.
*/
get_header(); ?>
<div id="primary" class="<?php
$category = get_the_category();
echo $category[0]->cat_name;
?>">
<div id="feature-container" class="full-width-container">
<div class="full-width-container content-page" id="tagline-wrapper">
<div id="left-black"></div>
<div class="page-width-container">
<div id="tagline-box">
<h1 class="category-title">Transactions</h1>
</div>
</div>
</div>
</div>
<div id="content-wrapper">
<div id="project-menu" class="page-width-container">
<?php wp_nav_menu(array('theme_location' => 'project-types')); ?>
</div>
<div id="content" role="main" >
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="story-container" class="module-container">
<div class="our-story">
<div class="story-image">
<?php
// check if the post has a Post Thumbnail assigned to it.
if (has_post_thumbnail()) {
the_post_thumbnail();
}
?>
</div>
<div class="story-text">
<article class="post" id="post-<?php the_ID(); ?>">
<div class="entry-container">
<h2><a href="<?php the_permalink() ?>#content" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<div class="project-details">
<p><span class="details-location"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_project-location', true);
wp_reset_query();
?></span><br />
<span class="details-funding"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_funding-type', true);
wp_reset_query();
?> | <?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_funding-source', true);
wp_reset_query();
?></span><br />
<span class="details-value"><?php
global $wp_query;
$postid = $wp_query->post->ID;
echo get_post_meta($postid, '_project-value', true);
wp_reset_query();
?></span></p>
</div>
<div class="entry">
<?php the_content(); ?>
<?php wp_link_pages(array('before' => __('Pages: ','html5reset'), 'next_or_number' => 'number')); ?>
</div>
<?php edit_post_link(__('Edit this entry','html5reset'), '<p>', '</p>'); ?>
</div>
</article>
</div>
</div>
</div>
<?php endwhile; endif; ?>
</div><!-- #content -->
</div>
</div><!-- #primary -->
<?php get_footer(); ?>
將$ per_page更改爲3以獲得3個帖子,並在while循環中使用計數器查看計數器是否大於2不要調用the_content()。@ Devonanne –
謝謝 - 你能舉一個例子說明你是怎麼做的改變上面的代碼?仍然不完全清楚哪些部分要改變。 – Devonanne
你好,你可以創建循環條件 –