我已在wordpress中创建了一个自定义帖子类型,方法是将以下内容添加到我的自定义主题function.php
中function oil_paintings_init() {
$args = array(
'labels' => array(
'name' => __( 'oil-paintings' ),
'singular_name' => __( 'oil-painting' ),
'rewrite' => array( 'slug' => 'oil-painting'),
),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'query_var' => true,
'menu_icon' => 'dashicons-format-image',
'supports' => array(
'title',
'editor',
'revisions',
'page-attributes',)
);
register_post_type( 'oil-paintings', $args );
}
add_action( 'init', 'oil_paintings_init' );
我创建了一个自定义页面模板,它循环显示我上面添加的自定义帖子类型的帖子。我希望一次显示5个帖子,并通过页面上的下一个和上一个链接休息。这是我使用过的代码:
<?php
$currentPage = (get_query_var('paged'))? get_query_var('paged') : 1;
$args =array(
'post_type'=>'oil-paintings',
'posts_per_page' => 5,
'nopaging' => false,
'paged' => $currentPage,
);
$wp_query = new WP_Query($args);
?>
<?php if($wp_query->have_posts()): while($wp_query->have_posts()) : $wp_query->the_post(); ?>
<div class="columns">
<img src="<?php the_field('image1'); ?>" alt="" />
<a href="<?php the_Permalink(); ?>"><?php the_title(); ?></a>
</div>
<?php endwhile;
next_posts_link("next");
previous_posts_link("prev");
endif;
wp_reset_postdata(); ?>
我面临的问题是当我在wordpress中启用永久链接时
'http://www.domainname.com/%postname%/' -->this does not work
下一个和上一个帖子链接停止工作,我得到一个页面未找到错误。如果我的永久链接设置为普通
,一切正常'http://www.domainname.com/?p=123' --> this works
这方面的任何帮助都得到了认可。 感谢
好吧我知道我哪里出错了。将重写移出标签数组解决了它。这是functions.php
中的工作代码 function oil_paintings_init() {
$args = array(
'labels' => array(
'name' => __( 'oil-paintings' ),
'singular_name' => __( 'oil-painting' )
),
'rewrite' => array( 'slug' => 'oil-painting'),
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'query_var' => true,
'menu_icon' => 'dashicons-format-image',
'supports' => array(
'title',
'editor',
'revisions',
'page-attributes',)
);
register_post_type( 'oil-paintings', $args );
}
add_action( 'init', 'oil_paintings_init' );