I found a solution that works! Code can be improved, but this is a start.
Put this in single.php
:
<?php /* 1. First check to see if single is in the category that is not allowed to be viewable through the single template: */
if (in_category('in-het-kort') ) {
/* 2. Do a loop to determine how many posts there are in a certain category. */
$args=array(
'cat' => 1036,
'showposts' => -1
);
$count=0;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();
/*Find out what the offset is for the current post */
$count++;
if ( $current_post == get_the_ID() ) {
$post_offset = $count;
}
endwhile;
}
wp_reset_query();
?>
<?php /* 3. Then construct the URL to redirect to. */ ?>
<?php
$postsperpage = get_option('posts_per_page');
$cat_page_number_notrounded = $post_offset / $postsperpage;
$cat_page_number = round($cat_page_number_notrounded, 0, PHP_ROUND_HALF_UP);
$redirect_url = get_bloginfo('url').'/categorie/in-het-kort/page/'.$cat_page_number.'#post_'.get_the_ID();
?>
<?php /* 4. Then redirect the user to this URL either via Javascript... */ ?>
<script>
window.location = "<?php echo $redirect_url; ?>"
</script>
<?php /* 5. ...Or via PHP, depending on your needs. */ ?>
<?php wp_redirect($redirect_url); exit; ?>
single.php
redundant)?single-cat.php
(where 'cat' is the slug of the category you intend this for), and copy the code ofcategory.php
in to that, but it appears that it doesn't exist in the hierarchy. Perhaps worth having a look though, as you may find it useful for the future - Template Hierarchy Codex.