这一点也不难,它只是将您的类别循环样式化到一个表中,如下所示:
<table>
<tr>
<th>Photo</th><th>Item Brand, Model</th><th>Description</th><th>PSI</th><th>GPM</th><th>RPM</th><th>HP</th><th>Stock No.</th>
</tr>
<?php
while (have_posts()){
the_post();
?>
<tr>
<td>
<?php
if(has_post_thumbnail()) {
the_post_thumbnail();
} else {
echo \'<img src="\'.get_bloginfo("template_url").\'/images/img-default.png" />\';
}
?>
</td>
<td>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</td>
<td>
<?php the_excerpt(); ?>
</td>
<td>
<?php echo get_post_meta($post->ID,\'PSI\',true); ?>
</td>
<td>
<?php echo get_post_meta($post->ID,\'GPM\',true); ?>
</td>
<td>
<?php echo get_post_meta($post->ID,\'RPM\',true); ?>
</td>
<td>
<?php echo get_post_meta($post->ID,\'HP\',true); ?>
</td>
<td>
<?php echo get_post_meta($post->ID,\'Stock_No\',true); ?>
</td>
</tr>
<?php
}
?>
</table>
它使用文章缩略图作为图像,名称作为标题,链接到“完整文章”,摘录作为描述,并假设您有名为:PSI、GPM、RPM、HP和Stock\\u No的自定义字段。
现在完成后,您可以使用自定义帖子类型,比如您称之为产品,并使用register_post_type.
add_action(\'init\', \'custom_products_post_type_init\');
function custom_products_post_type_init()
{
$labels = array(
\'name\' => _x(\'Products\', \'post type general name\'),
\'singular_name\' => _x(\'Product\', \'post type singular name\'),
\'add_new\' => _x(\'Add New\', \'Product\'),
\'add_new_item\' => __(\'Add New Product\'),
\'edit_item\' => __(\'Edit Product\'),
\'new_item\' => __(\'New Product\'),
\'view_item\' => __(\'View Product\'),
\'search_items\' => __(\'Search Products\'),
\'not_found\' => __(\'No Products found\'),
\'not_found_in_trash\' => __(\'No Products found in Trash\'),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Products\'
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'taxonomies\' => array(\'category\', \'post_tag\'),
\'supports\' => array(\'title\',\'editor\',\'author\',\'thumbnail\',\'excerpt\',\'comments\',\'custom-fields\')
);
register_post_type(\'product\',$args);
}
如果这样做,只需在循环上方添加一个简单的参数,使用query\\u post进行查询,让它知道您正在使用自定义的post类型:
query\\u posts(\'post\\u type=\'product\');
希望这有帮助