$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>Permalinks problem - Category pages don't work|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

Permalinks problem - Category pages don't work

matteradmin9PV0评论

I tried many different solutions to get category page for wordpress to work. Here are my settings in wordpress.

I like to have structure "domainname/name of the post/" but when I want to go to individual category page I receive an error that it doesn't exist.

If I change permalink structure from /%postname%/ to /%postname%/%category%/ everything works fine but the structure of the post is domainname/category/name of the post/ and I don't want that. mydomain/health/ doesn't work if I keep the name of the post only. It works when I change it to /%postname%/%category%/

I tried to remove . in base category and it doesn't make any difference.

These are my entries in function.php

    <?php
function comment_reply_text( $link ) {
$link = str_replace( 'Reply', 'Odgovori', $link );
return $link;
}
add_filter( 'comment_reply_link', 'comment_reply_text' );
?>
<?php
function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}
?>
<?php
function wpsites_query( $query ) {
if ( $query->is_home() && $query->is_main_query() ) { 
$query->set( 'posts_per_page', 10 ); }
}
add_action( 'pre_get_posts', 'wpsites_query' );
?>
<?php
function custom_excerpt($word_count_limit) {
    $content = wp_strip_all_tags(get_the_content() , true );
    echo wp_trim_words($content, $word_count_limit);
}
?>
<?php
add_filter( 'term_link', function($termlink){ return str_replace('/./', '.', $termlink); }, 10, 1 );
?>

Any ideas?

I tried many different solutions to get category page for wordpress to work. Here are my settings in wordpress.

I like to have structure "domainname/name of the post/" but when I want to go to individual category page I receive an error that it doesn't exist.

If I change permalink structure from /%postname%/ to /%postname%/%category%/ everything works fine but the structure of the post is domainname/category/name of the post/ and I don't want that. mydomain/health/ doesn't work if I keep the name of the post only. It works when I change it to /%postname%/%category%/

I tried to remove . in base category and it doesn't make any difference.

These are my entries in function.php

    <?php
function comment_reply_text( $link ) {
$link = str_replace( 'Reply', 'Odgovori', $link );
return $link;
}
add_filter( 'comment_reply_link', 'comment_reply_text' );
?>
<?php
function catch_that_image() {
  global $post, $posts;
  $first_img = '';
  ob_start();
  ob_end_clean();
  $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  $first_img = $matches [1] [0];

  if(empty($first_img)){ //Defines a default image
    $first_img = "/images/default.jpg";
  }
  return $first_img;
}
?>
<?php
function wpsites_query( $query ) {
if ( $query->is_home() && $query->is_main_query() ) { 
$query->set( 'posts_per_page', 10 ); }
}
add_action( 'pre_get_posts', 'wpsites_query' );
?>
<?php
function custom_excerpt($word_count_limit) {
    $content = wp_strip_all_tags(get_the_content() , true );
    echo wp_trim_words($content, $word_count_limit);
}
?>
<?php
add_filter( 'term_link', function($termlink){ return str_replace('/./', '.', $termlink); }, 10, 1 );
?>

Any ideas?

Share Improve this question edited Oct 21, 2018 at 14:28 fuxia 107k39 gold badges255 silver badges461 bronze badges asked Oct 21, 2018 at 14:27 TechuserTechuser 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I don't think you can use a period in the category base field. If you are looking to remove the category base completely there is a plugin for that - https://wordpress/plugins/remove-category-base-littlebizzy/

Post a comment

comment list (0)

  1. No comments so far