Alecaddd / Sunset-theme

Premium WordPress theme built during this series of tutorials: https://www.youtube.com/playlist?list=PLriKzYyLb28kpEnFFi9_vJWPf5-_7d3rX
GNU General Public License v2.0
330 stars 354 forks source link

Fix for multiple Gallery Posts #2

Closed h2ostek closed 8 years ago

h2ostek commented 8 years ago

Added the ID from post to know what post the user is on to handle the thumbnails correctly.

Alecaddd commented 8 years ago

Good suggestion! I will edit a bit the code to avoid all those repeated declarations

h2ostek commented 8 years ago

I'm learning a lot from you. I enjoy all of your vids. For the next challenge from Part 38, here is my solution. I use the variable $uriValues instead of $flipped... I got rid of the long if statement and used a switch statement. What do you think?

if ( $archive != '0' ) { $archVal = explode( '/', $archive ); $uriValues = array_flip($archVal);

  **switch ( isset( $uriValues ) ) {
     case $uriValues['category'] :
        $type = 'category_name';
        $key = 'category';
        break;
     case $uriValues['tag'] :
        $type = 'tag';
        $key = $type;
        break;
     case $uriValues['author'] :
        $type = 'author';
        $key = $type;
        break;
  }**

  $currKey = array_keys( $archVal, $key );                  
  $nextKey = $currKey[0] + 1;
  $value   = $archVal[$nextKey];
  $args[$type] = $value;

  //check page trail and remove "page" value
  if ( isset( $uriValues['page'] ) ) {
     $pageVal = explode( 'page', $archive );
     $page_trail = $pageVal[0];
  } else {
     $page_trail = $archive;
  }

} else { $page_trail = '/'; }

Alecaddd commented 8 years ago

I love it! It's a great solution, especially because you reduced the number of isset() to just one. "if else" and "switch" are identical in performance if you only check for static variables. If you use a function tho, switch is better because you can avoid to call that function multiple times. Awesome!

I will integrate this in the next tutorial!

h2ostek commented 8 years ago

Glad you like it. I look forward to your next tut(s). Your designer series is very inspiring as well dude.