我现在束手无策了。真的需要一些帮助!这是设置。。。
在我的functions.php:
// Register the events post type
function events() {
$labels = array(
\'name\' => _x(\'Evenemang\', \'\'),
\'singular_name\' => _x(\'Evenemang\', \'\'),
\'menu_name\' => _x(\'Evenemang\', \'\'),
\'name_admin_bar\' => _x(\'Evenemang\', \'\'),
\'add_new\' => _x(\'Skapa ny\', \'evenemang\'),
\'add_new_item\' => __(\'Skapa nyt evenemang\'),
\'search_items\' => __(\'Sök evenemang\'),
\'not_found\' => __(\'Hittade inga evenemang.\'),
\'not_found_in_trash\' => __(\'Inga evenemang hittades i papperskorgen.\'),
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_in_menu\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'evenemang\'),
\'query_var\' => \'evenemang\',
\'menu_icon\' => \'dashicons-calendar-alt\',
\'supports\' => array(\'title\', \'editor\', \'thumbnail\')
);
register_post_type(\'evenemang\', $args);
}
add_action(\'init\', \'events\');
// Register the recipes post type
function recipes() {
$labels = array(
\'name\' => _x(\'Recept\', \'\'),
\'singular_name\' => _x(\'Recept\', \'\'),
\'menu_name\' => _x(\'Recept\', \'\'),
\'name_admin_bar\' => _x(\'Recept\', \'\'),
\'add_new\' => _x(\'Skapa ny\', \'recept\'),
\'add_new_item\' => __(\'Skapa ny recept\'),
\'search_items\' => __(\'Sök recept\'),
\'not_found\' => __(\'Hittade inga recept.\'),
\'not_found_in_trash\' => __(\'Inga recept hittades i papperskorgen.\'),
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_in_menu\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'recept\'),
\'query_var\' => \'recept\',
\'menu_icon\' => \'dashicons-carrot\',
\'supports\' => array(\'title\', \'thumbnail\')
);
register_post_type(\'recept\', $args);
}
add_action(\'init\', \'recipes\');
对于这两个类型中的每一个,我都有一个存档{post\\u type}。php,我正在使用
<?php echo paginate_links(); ?>
要显示分页链接,请执行以下操作
archive-evenemang.php:<?php get_header(); ?>
<div class="list">
<?php
$today = date(\'Ymd\');
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => 8,
\'post_type\' => \'evenemang\',
\'meta_key\' => \'event_date\',
\'orderby\' => \'meta_value_num\',
\'order\' => \'ASC\',
\'paged\' => $paged,
\'meta_query\' => array(
array(
\'key\' => \'event_date\',
\'compare\' => \'>=\',
\'value\' => $today
)
)
);
?>
<?php $posts = get_posts($args); foreach ($posts as $post) : setup_postdata($post); ?>
<h1><?php the_title(); ?></h1>
<?php endforeach; wp_reset_postdata(); ?>
</div>
<div class="pagination">
<?php echo paginate_links(); ?>
</div>
<?php get_footer(); ?>
这是
archive-recept.php:<?php get_header(); ?>
<div class="list">
<?php
$today = date(\'Ymd\');
$paged = (get_query_var(\'paged\')) ? get_query_var(\'paged\') : 1;
$args = array(
\'posts_per_page\' => 8,
\'post_type\' => \'recept\',
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'paged\' => $paged
);
?>
<?php $posts = get_posts($args); foreach ($posts as $post) : setup_postdata($post); ?>
<h1><?php the_title(); ?></h1>
<?php endforeach; wp_reset_postdata(); ?>
</div>
<div class="pagination">
<?php echo paginate_links(); ?>
</div>
<?php get_footer(); ?>
正如您所看到的,它们在函数中的设置完全相同。php,并使用基本相同的归档模板(对查询中的$args稍作调整)。
“evenemang”页面运行良好,它显示结果、分页按钮,我可以访问mydomain.com/evenemang/page/2/.
“接收”页面也可以工作,它显示结果,但没有分页按钮,如果我尝试访问mydomain.com/recept/page/2/ 它只会出现在头版。
为什么它对其中一个有效而对另一个无效?是否需要更改paginate_links()
作用使用时出现问题get_query_var(\'paged\')
在多个存档上?它是一个。访问问题?