$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'); ?>Template and URL parameter problem|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)

Template and URL parameter problem

matteradmin9PV0评论

I have a template that lists posts by categories. It works great with the exception of categories with a space in their name.

I simply want to use a URL parameter to select the category and it only works if there is no space. Adding a %20 doesn't help.

It works great when the category is a single word but doesn't work when the category has a space. When I try to call it like this "https://url/?template=oneword" it's fine, when I try to call it with https://url/?firstword%20secondword" it's no good.

Using the slug doesn't work either; single word categories are fine and multi-word categories are blank (even though the slug is a single word).

Here's the template code I'm using:

$args = array(
'orderby' => 'name',
'parent' => 0,
'name' => $category_name
);

$categories = get_categories( $args );
foreach  ($categories as $category) {
echo '<h2>'.$category->name.'</h2>';
echo '<ul>';

foreach (get_posts('cat='.$category->term_id) as $post) {
    setup_postdata( $post );
    echo '<li><a href="'.get_permalink($post->ID).'">'.get_the_title().'</a></li>';   
}  
echo '</ul>';

Any ideas?

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far