0

hi

How do I convert links from

mysite/tv/title-post?go=seasons
mysite/tv/title-post?go=characters

to

mysite/tv/title-post/seasons
mysite/tv/title-post/characters

This code

    <?php
    $post_id = $_GET["go"];
     ?>
    
    <nav>
    <ul class="subNav">
    <li class="<?php echo $post_id == '' ? 'selected' : ''; ?>"><a href="<?php the_permalink() ?>">info</a></li>
    <li class="<?php echo $post_id == 'seasons' ? 'selected' : ''; ?>"><a href="<?php the_permalink() ?>?go=seasons">seasons</a></li>
    <li class="<?php echo $post_id == 'characters' ? 'selected' : ''; ?>"><a href="<?php the_permalink() ?>?go=characters">characters</a></li>
    </ul>
    </nav>
    
    <?php 
    if($post_id == 'seasons'):
        $setion = get_template_part('inc/parts/single/seasons');
    elseif($post_id == 'characters'):
        $setion = get_template_part('inc/parts/single/characters');
    else:
        $setion = get_template_part('inc/parts/single/info');
    endif;
     ?>

Any help, please?
I am tired of the experiences ^^

2
  • What is "go"? Is that a taxonomy (like a category or tag)? If so, have you registered that as a taxonomy?
    – JakeParis
    Commented Feb 10, 2021 at 1:30
  • Not category or tag ... just a regular name that I chose to go to the target content for clarity
    – davnshi
    Commented Feb 10, 2021 at 10:32

1 Answer 1

0

Probably the easiest way to solve this would be to add classes to your body tag based on the value of the parameter. You would just want to be sure to sanitize it. You can add classes to the body using the body_class filter which feeds in all the current classes as an array.

You might try something like the following at the top of your template file:

add_filter('body_class', function($classes) {
  if( ! isset($_GET['view']) )
    return $classes;
  
  $classes[] = "post-layout-" . esc_attr($_GET['view']);

  return $classes;
});

Now based on the body having a class of post-layout-list or post-layout-grid, you could style your posts list differently.

This has the advantage of less php logic to juggle. Note that this answer is meant to help think through the strategy, rather than as code that you can just copy and paste.

3
  • Can you apply it to my code I did not understand exactly what you mean.
    – davnshi
    Commented Feb 9, 2021 at 20:04
  • I have modified the code that I am working on
    – davnshi
    Commented Feb 9, 2021 at 21:06
  • Can you amend my code, please
    – davnshi
    Commented Feb 10, 2021 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.