Giter VIP home page Giter VIP logo

Comments (2)

mrfsrf avatar mrfsrf commented on September 2, 2024

Regarding optional route patterns, try /:one?/:two?/:three?
Haven't tried it but I think it should work.

Are you sure your WP_Query is ok?

Update:

Looks like I was wrong, there is no logic for checking for optional patterns.
You can Extend Routes class and add that logic.

Optional route patterns work (Didn't look in AltoRouter.php)

from routes.

mrfsrf avatar mrfsrf commented on September 2, 2024

you can write it like this:

// Routes::map('verzeichnis', 'my_cb');
// Routes::map('verzeichnis/:country', 'my_cb');
// Routes::map('verzeichnis/:country/:city', 'my_cb');
// Routes::map('verzeichnis/:country/:city/:rechtsgebiet', 'my_cb');
Routes::map('verzeichnis/:country?/:city?/:rechtsgebiet?', 'my_cb');

function my_cb($params) {
  
  foreach($params as $key => $value){
    switch($key){
      case 'rechtsgebiet':
        $filename = '-schwerpunk';
        break;
      case 'city':
        $filename = '-city';
        break;
      case 'country':
        $filename = '-country';
        break;
      default:
        $filename = '';
        break;
    }
  }

  $query = array(
    'posts_per_page'  => 30,
    'country'         => $params['country'], // is this correct WP_Query?
    'city'            => $params['city'],
    'rechtsgebiet'    => $params['rechtsgebiet'],
    // Add this if you want to optimize query
    'no_found_rows'   => true,
    'ignore_sticky_posts' => true,
  );

  Routes::load(get_stylesheet_directory() . '/directory/directory' .$filename. '.php', $params, $query);
}

From the Documentation

$query
The query you want to use, it can accept a string or array just like Timber::get_posts -- use the standard WP_Query syntax (or a WP_Query object too)

from routes.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.