我整晚都在阅读和搜索。我以前遇到过 CPT 分页的问题,但这真的让我抓狂。我将我正在构建的网站上传到http://koovay.com/Kingship/。当前版本 3.7.1 。我的原始代码是:
<?php
$temp = $wp_query;
$wp_query = null;
$wp_query = new WP_Query();
$wp_query->query('showposts=20&post_type=portfolio'.'&paged='.$paged); ?>
<?php while ($wp_query->have_posts()) : $wp_query->the_post();
$featuredImage = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
$permalink = get_permalink( $id );
?>
-- 循环的东西 --
<?php endwhile; ?>
<nav class="paged text-center">
<?php previous_posts_link('« Newer') ?>
<?php next_posts_link('Older »') ?>
</nav>
<?php
$wp_query = null;
$wp_query = $temp; // Reset
?>
我使用自定义帖子类型 UI 并创建了我的 CPT:
add_action('init', 'cptui_register_my_cpt_portfolio');
function cptui_register_my_cpt_portfolio() {
register_post_type('portfolio', array(
'label' => 'Portfolio',
'description' => 'Your portfolio for showcasing yo bitch ass work!',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'post',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'works', 'with_front' => 1),
'query_var' => true,
'has_archive' => true,
'menu_position' => '5',
'supports' => array('title','editor','thumbnail'),
'taxonomies' => array('category'),
'labels' => array (
'name' => 'Portfolio',
'singular_name' => 'Work',
'menu_name' => 'Portfolio',
'add_new' => 'Add Work',
'add_new_item' => 'Add New Work',
'edit' => 'Edit',
'edit_item' => 'Edit Work',
'new_item' => 'New Work',
'view' => 'View Work',
'view_item' => 'View Work',
'search_items' => 'Search Portfolio',
'not_found' => 'No Portfolio Found',
'not_found_in_trash' => 'No Portfolio Found in Trash',
'parent' => 'Parent Work',
)
) ); }
我阅读了一篇关于将重写名称更改为 CPT 名称以外的内容的帖子,因此我将其更改为“工作”。
但这触发了 404。我尝试了一些 alt。我可以发布运行循环和分页的版本。
老实说,我真的希望有人能给我一些帮助。快疯了……谢谢!