Closed h2ostek closed 8 years ago
Good suggestion! I will edit a bit the code to avoid all those repeated declarations
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 = '/'; }
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!
Glad you like it. I look forward to your next tut(s). Your designer series is very inspiring as well dude.
Added the ID from post to know what post the user is on to handle the thumbnails correctly.