2013-11-15 103 views
0

我一直在阅读和搜索整晚。我之前在CPT分页方面遇到过问题,但这真的让我发疯。我将我正在构建的网站上传到http://koovay.com/Kingship/。 当前版本3.7.1。我原来的代码是:WordPress中不寻常的自定义帖子类型分页问题?

<?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('&laquo; Newer') ?> 
<?php next_posts_link('Older &raquo;') ?> 
</nav> 

<?php 
$wp_query = null; 
$wp_query = $temp; // Reset 
?> 

进出口使用自定义文章类型的用户界面和创建了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。运行循环和分页的版本我可以发布。

老实说,我真的希望有人能够给我一些帮助。疯了... 谢谢!

回答

0

我用GenerateWP创建下面的代码。它应该工作。

if (! function_exists('Portfolio')) { 

功能组合(){

$labels = array(
    'name'    => 'Portfolio Items', 
    'singular_name'  => 'Portfolio', 
    'menu_name'   => 'Portfolio ', 
    'parent_item_colon' => 'Parent Portfolio ', 
    'all_items'   => 'All Portfolio ', 
    'view_item'   => 'View Portfolio ', 
    'add_new_item'  => 'Add New Portfolio ', 
    'add_new'    => 'New Portfolio ', 
    'edit_item'   => 'Edit Portfolio ', 
    'update_item'   => 'Update Portfolio ', 
    'search_items'  => 'Search Portfolio ', 
    'not_found'   => 'No Portfolio Items FOund', 
    'not_found_in_trash' => 'No products found in Trash', 
); 
$args = array(
    'label'    => 'portfolio ', 
    'description'   => 'portfolio ', 
    'labels'    => $labels, 
    'supports'   => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', 'post-formats',), 
    'hierarchical'  => false, 
    'public'    => true, 
    'show_ui'    => true, 
    'show_in_menu'  => true, 
    'show_in_nav_menus' => true, 
    'show_in_admin_bar' => true, 
    'menu_position'  => 5, 
    'menu_icon'   => '', 
    'can_export'   => true, 
    'has_archive'   => true, 
    'exclude_from_search' => false, 
    'publicly_queryable' => true, 
    'capability_type'  => 'page', 
); 
register_post_type('portfolio ', $args); 

}

//勾入 '初始化' 动作 ADD_ACTION( '初始化', '组合',0);

}

相关问题