ThemeFuse / Unyson

A WordPress framework that facilitates the development of WP themes
http://unyson.io
922 stars 217 forks source link

[feature] Portfolio extension tags #1159

Closed danyj closed 8 years ago

danyj commented 8 years ago

Is there any way that you can add tags to portfolio extension ?

puyaalexxx commented 8 years ago

Add this

$labels = array(
            'name' => __('Tags','fw' ),
            'singular_name' => __('Tag', 'fw'),
            'search_items' => __('Search Tags','fw'),
            'popular_items' => __( 'Popular Tags','fw' ),
            'all_items' => __('All Tags','fw'),
            'parent_item' => null,
            'parent_item_colon' => null,
            'edit_item' => __('Edit Tag','fw'),
            'update_item' => __('Update Tag','fw'),
            'add_new_item' => __('Add New Tag','fw'),
            'new_item_name' => __('New Tag Name','fw'),
            'separate_items_with_commas' => __( 'Separate tags with commas','fw' ),
            'add_or_remove_items' => __( 'Add or remove tags','fw' ),
            'choose_from_most_used' => __( 'Choose from the most used tags','fw' ),
        );

        register_taxonomy('tags', 'fw-portfolio', array(
            'hierarchical' => false,
            'labels' => $labels,
            'public' => true,
            'show_ui' => true,
            'update_count_callback' => '_update_post_term_count',
            'query_var' => true,
            'rewrite' => array('slug' => 'portfolio-tag')
        ));

on init action

add_action( 'init', 'function_name');
danyj commented 8 years ago

@puyaalexxx thnx for the reply I did not see it at all , but we cant do this from theme otherwise it wont pass TF theme check , this needs to be done on plugin level

http://prntscr.com/9sorc7

danyj commented 8 years ago

@moldcraft I see you monitor this, I need to code the portfolio page , is it ok for me to add this

function _action_fw_ext_portfolio_tags( ) {

    $labels = array(
        'name' => __('Tags','fw' ),
        'singular_name' => __('Tag', 'fw'),
        'search_items' => __('Search Tags','fw'),
        'popular_items' => __( 'Popular Tags','fw' ),
        'all_items' => __('All Tags','fw'),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __('Edit Tag','fw'),
        'update_item' => __('Update Tag','fw'),
        'add_new_item' => __('Add New Tag','fw'),
        'new_item_name' => __('New Tag Name','fw'),
        'separate_items_with_commas' => __( 'Separate tags with commas','fw' ),
        'add_or_remove_items' => __( 'Add or remove tags','fw' ),
        'choose_from_most_used' => __( 'Choose from the most used tags','fw' ),
    );

    register_taxonomy('tags', 'fw-portfolio', array(
        'hierarchical' => false,
        'labels' => $labels,
        'public' => true,
        'show_ui' => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var' => true,
        'rewrite' => array('slug' => 'portfolio-tag')
    )); 

}

add_action( 'init', '_action_fw_ext_portfolio_tags');

after this filter https://github.com/ThemeFuse/Unyson-Portfolio-Extension/blob/master/hooks.php#L64

until you add it to the extension ?

danyj commented 8 years ago

@moldcraft this snipp wont work , there are no tags in the $post tags are in backend http://prntscr.com/9y3fbw

but this is empty

wp_get_post_tags(get_the_ID())
ghost commented 8 years ago

Please test.

danyj commented 8 years ago

@moldcraft the filter works , thnx!

but we have no tag view and the links cant find the tagged projects

$tags = wp_get_post_tags($post->ID); 
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
$tag_link = get_tag_link( $tag->term_id );

$html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
$html .= "{$tag->name}</a> ";
}
$html .= '</div>';
ghost commented 8 years ago

Do you know how to fix that and create a pull request?

danyj commented 8 years ago

Honestly no idea , I never dealt with it. So far I see from all other themes portfolios there needs to be custom tax for tags http://prntscr.com/b3kxzw and we cant use the wp default which is what we just did , thus the link is tryng to find blog posts with the tags and not projects

danyj commented 8 years ago

so we need tax

fw-porfolio-tag  

edit-tags.php?taxonomy=fw-portfolio-tag&post_type=fw-portfolio

just like we have

fw-portfolio-category

edit-tags.php?taxonomy=fw-portfolio-category&post_type=fw-portfolio
ghost commented 8 years ago

Thank you

danyj commented 8 years ago

if you decide and find time to add it , dont go nuts , just redirect the view to portfolio archive

danyj commented 8 years ago

@moldcraft I am not sure if this will help you

but with this filter

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if( is_tag() ) {
    $post_type = get_query_var('post_type');
    if($post_type){
        $post_type = $post_type;
    }else{
        $post_type = array('post','fw-portfolio','nav_menu_item');
    }
    $query->set('post_type',$post_type);
    return $query;
    }
}

I get the tag view but is posts tag view mixing projects and blog posts and I am not even sure if that query is 100% ok.

I think that these 2 ( blog posts, projects ) should not be mixed and each should have own tag view ,

danyj commented 8 years ago

yeah that is not right , even some menu assignments dont play well,

danyj commented 8 years ago

yes , they should be separated , even woocommerce has product-tag and the view redirects to woo archive displaying products with that tag