2

我和我的朋友都完全不知道这里发生了什么。任务是从一个帖子到下一个帖子有标准的分页链接。我们可以看到从 page/2/、page/3/ 等开始的页面,但内容没有改变。

这是我们在自定义模板中得到的内容。

 <?php
 /**
 * The Template for displaying all single posts.
 *
 * Template Name: Portfolio
 *
 * @package WordPress
 * @subpackage Boilerplate
 * @since Boilerplate 1.0
 */

 get_header();

 // Enable Pagination
 $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

 $args = array(
 'post_type' => array(
 'portfolio'
 ),
 'orderby' => 'date',
 'posts_per_page' => 1,
 'paged'=>$paged
 );

 $the_query = new WP_Query( $args );

 while ( $the_query->have_posts() ) : $the_query->the_post(); 

 ?>

 <article id="item<?php the_ID(); ?>" <?php post_class('post portfolio'); ?>>
   <h2><?php the_title(); ?></h2>
   <div>
     <?php the_content(); ?>
   </div>
 </article>

 <?php endwhile; ?>
     <?php next_posts_link('« Older Entries') ?>
     <?php previous_posts_link('Newer Entries »') ?>
 <?php wp_reset_postdata(); ?>

 <?php get_footer(); ?>

在functions.php的底部有一些自定义的帖子类型脚本......

// Custom Post Type

function foggin_Portfolio() {
$labels = array(
    'name'               => _x( 'Portfolio', 'post type general name' ),
    'singular_name'      => _x( 'Portfolio', 'post type singular name' ),
    'add_new'            => _x( 'Add New', 'book' ),
    'add_new_item'       => __( 'Add New Item' ),
    'edit_item'          => __( 'Edit item' ),
    'new_item'           => __( 'New Item' ),
    'all_items'          => __( 'All Items' ),
    'view_item'          => __( 'View Item' ),
    'search_items'       => __( 'Search items' ),
    'not_found'          => __( 'No item' ),
    'not_found_in_trash' => __( 'No items found in the Trash' ),
    'parent_item_colon'  => '',
    'menu_name'          => 'Portfolio'
);
$args = array(
    'labels'        => $labels,
    'description'   => 'Holds portfolio items and portfolio specific data',
    'public'        => true,
    'menu_position' => 5,
    'rewrite'       => array('slug'=>'','with_front'=>false),
    'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'custom-fields', 'taxonomies'),
    'taxonomies'    => array('post_tag'),
    'has_archive'   => true,
);
register_post_type( 'portfolio', $args );
}

add_action( 'init', 'foggin_Portfolio' );

function portfolio_messages( $messages ) {
    global $post, $post_ID;
    $messages['portfolio'] = array(
        0 => '',
        1 => sprintf( __('Portfolio item updated. <a href="%s">View item</a>'), esc_url( get_permalink($post_ID) ) ),
        2 => __('Custom field updated.'),
        3 => __('Custom field deleted.'),
        4 => __('Product updated.'),
        5 => isset($_GET['revision']) ? sprintf( __('Portfolio item restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
        6 => sprintf( __('Portfolio item published. <a href="%s">View item</a>'), esc_url( get_permalink($post_ID) ) ),
        7 => __('Portfolio item saved.'),
        8 => sprintf( __('Portfolio item submitted. <a target="_blank" href="%s">Preview item</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
        9 => sprintf( __('Portfolio item scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview item</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
        10 => sprintf( __('Portfolio item draft updated. <a target="_blank" href="%s">Preview item</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
        );
        return $messages;
    }

    add_filter( 'post_updated_messages', 'portfolio_messages' );


    function portfolio_taxonomies() {
        $labels = array(
        'name'              => _x( 'Categories', 'taxonomy general name' ),
        'singular_name'     => _x( 'Category', 'taxonomy singular name' ),
        'search_items'      => __( 'Search Categories' ),
        'all_items'         => __( 'All Categories' ),
        'parent_item'       => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item'         => __( 'Edit Category' ),
        'update_item'       => __( 'Update Category' ),
        'add_new_item'      => __( 'Add New Category' ),
        'new_item_name'     => __( 'New Category' ),
        'menu_name'         => __( 'Categories' ),
    );
    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
    );
    register_taxonomy( 'portfolio_category', 'portfolio', $args );
}
add_action( 'init', 'portfolio_taxonomies', 0 );

?>

想法,想法,建议会非常有帮助我认为公平地说我们都对此感到困惑。

4

1 回答 1

0

这可能听起来很傻,但是将您的永久链接重置为默认值,然后恢复为您想要的格式。将帖子类型添加到functions.php后需要重写.htaccess文件

您将rewrite选项设置为false的操作也可能导致问题。如果 WP 不清楚重写 yourdomain.com/page/2/ 那么重写为 true 使其成为 yourdomain.com/portfolio/page/2/

其他一切似乎都符合您的查询。

于 2013-06-16T23:37:10.587 回答