Forum Replies Created

Viewing 7 replies - 1 through 7 (of 7 total)
  • Forum: Hacks
    In reply to: Custom taxonomy as homepage

    You could still easily add it to your theme and have an option to select the category from a settings page for when it changes. It could also be a plugin, but either way you’ll need a settings page to use the output of get_object_taxonomies as your options:

    $custom_taxonomies_array = get_object_taxonomies('custom_post_slug');

    You can then modify the instuctions for changing the post type that’s used on the front page for categories, and grab the option you’ve saved on your settings page and insert it as follows into your functions.php or elsewhere in your plugin if you don’t want it as a part of your theme:

    // Show category from option on home page
    add_action('pre_get_posts', 'change_front_page_main_query_to_custom_taxonomy');
    
    function change_front_page_main_query_to_custom_taxonomy($query) {
    	if (is_home() && $query->is_main_query())
    		$query->set('cat', get_option('option_from_dropdown_on_settings_page'));
    	return $query;
    }

    I don’t know if it’s improper usage or the plugin, but making the following change to class-frontend.php makes the filter I previously mentioned work properly for me. The commented line is the existing plugin code and the line below it the adjustment which makes it work properly for me.

    foreach ( $whitelisted_extravars as $get ) {
    	//if ( isset( $_GET[trim( $get )] ) ) {
    	if ( get_query_var( trim( $get ) ) ) {
    		$properurl = '';
    	}
    }

    Would like to know the same. Seemingly, :

    add_filter('wpseo_whitelist_permalink_vars', 'whitelist_yoasts_redirect'));
    function whitelist_yoasts_redirect($whitelisted_extravars) {
    	$whitelisted_extravars = array('my_query_var');
    	return $whitelisted_extravars;
    }

    However, no luck.

    Plugin Author Josh Davis

    (@maxxsnake)

    That sounds like a pain. I’ve added the options for labels now so that when you save them, they’ll remain even after updates. It also makes it easier for the average user to control the labels, since most aren’t comfortable editing markup.

    Plugin Author Josh Davis

    (@maxxsnake)

    Done

    Coincidentally, I’m also using the top code and needed to implement something at the sub-menu level. You can just add the second function into the first, then call the first walker. Mine looks like:

    class description_walker extends Walker_Nav_Menu
    {
          function start_el(&$output, $item, $depth, $args)
          {
               global $wp_query;
               $indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
    
               $class_names = $value = '';
    
               $classes = empty( $item->classes ) ? array() : (array) $item->classes;
    
               $class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
               $class_names = ' class="'. esc_attr( $class_names ) . '"';
    
               $output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
    
               $attributes  = ! empty( $item->attr_title ) ? ' title="'  . esc_attr( $item->attr_title ) .'"' : '';
               $attributes .= ! empty( $item->target )     ? ' target="' . esc_attr( $item->target     ) .'"' : '';
               $attributes .= ! empty( $item->xfn )        ? ' rel="'    . esc_attr( $item->xfn        ) .'"' : '';
               $attributes .= ! empty( $item->url )        ? ' href="'   . esc_attr( $item->url        ) .'"' : '';
    
               $prepend = '<div class="top sans">';
               $append = '</div>';
               $description  = ! empty( $item->title ) ? '<div class="bottom">'.esc_attr( $item->attr_title ).'</div>' : '';
    
               if($depth != 0)
               {
                         $description = $append = $prepend = "";
               }
    
                $item_output = $args->before;
                $item_output .= '<a'. $attributes .'>';
                $item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
                $item_output .= $description.$args->link_after;
                $item_output .= '</a><div class="hidden"><div class="back"></div></div>';
                $item_output .= $args->after;
    
                $output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
    		}
    
    		function start_lvl(&$output, $depth) {
    		    $indent = str_repeat("\t", $depth);
    		    $output .= "\n$indent<ul class=\"sub-menu level-".$depth."\"><span></span>\n";
    		}
    }

    Although I modified a few other things internally as needed and haven’t finished modding the second part (thanks for that) yet, but it is exporting the markup into the sub-menu appropriately.

    This was giving me trouble, too, until I caught later in the documentation it says

    _builtin
    (boolean) (not for general use) Whether this post type is a native or “built-in” post_type. Note: this Codex entry is for documentation – core developers recommend you don’t use this when registering your own post type
    Default: false
    ‘false’ – default this is a custom post type
    ‘true’ – this is a built-in native post type (post, page, attachment, revision, nav_menu_item)

    Note that they’re now calling it an ‘attachment’ instead of ‘mediapage’ – in my example making the switch took care of business as needed.

Viewing 7 replies - 1 through 7 (of 7 total)