Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #658735

    Hi Enfold-Team, i want to show the actual associated category in a posting-page.
    Here i found an example with a shown tag: http://kriesi.at/themes/enfold/2014/04/19/youth-is-fun-make-sure-it-stays-that-way/ and this speaker-shopping productpage https://mo-sound.com/de/shop/kugellautsprecher-schwarz-classic/

    Is it possible to do this with a post category?
    thanks!

    #659262

    btw, here is our website:

    #659654

    Hi,

    Thank you for using Enfold.

    Are you referring to the “categories” widget? Go to the Appearance > Widgets panel then add the “Categories” widget.

    Best regards,
    Ismael

    #662124

    hi ismael, no i mean a link in the article. like “Tags: econ, lifestyle” at here http://kriesi.at/themes/enfold/2014/04/19/youth-is-fun-make-sure-it-stays-that-way/

    #663182

    Hi,

    I see. Please edit the includes > loop-index.php file. Look for this code:

    	if(has_tag())
                	{
                    	echo '<span class="blog-tags minor-meta">';
                    	the_tags('<strong>'.__('Tags:','avia_framework').'</strong><span> ');
                    	echo '</span></span>';
                	}
    

    Below that line, add this:

    //categories on single post
                	if(has_category())
                	{
                    	echo '<span class="blog-categories minor-meta">';
    					echo '<strong>'.__('Categories:','avia_framework').'</strong><span> ';
                    	the_category(' ');
                    	echo '</span></span>';
                	}
    

    Best regards,
    Ismael

    #665394

    thanks, it works well when the default editor is activated.
    im sad sad to say to have to use the advanced editor. is there also a way (in the best case with my prideful child-theme)?
    thanks!

    #665430

    It’s really not good looking but working.
    I had the same problem with SKU and Categories, which DO appear in the default editor but not in the advanced editor, so I had to manually write them in. It creates the shortcode [display_sku_cat]. Just try it out.
    Create a new .php file and put it in the plugins folder. You can just adapt it to your needs, which should be pretty easy to do. That’s coming from a php newbie who wrote this – me .. ;)

    
    <?php
    /*
    Plugin Name: Display Article Number and Categories
    Description: Creates a shortcode, [display_sku_cat id="n"], that displays the article number and categories of any WooCommerce product.
    Version: 1.0
    Author: Duke
    Requires: PHP5, WooCommerce Plugin
    */
    
    if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ){
    add_shortcode('display_sku_cat', 'display_sku_cat_shortcode');
    }
    
    function display_sku_cat_shortcode($atts) {
    	global $post;
    	
    	extract(shortcode_atts(array(
    		'id' => $post->ID,
    		'link' => 'true',
    	), $atts));
    
    	if($link==='true'|$link==='false') {
    		$link = ($link === 'true');
    	}
    	
    	if(get_post_type($id)=='product'){
    		ob_start();
    		display_sku_cat($id);
    		return ob_get_clean();
    	}else{
    		return "";
    	}
    
    }
    
    function display_sku_cat($id="", $permalink=false ){
    	global $wpdb;
    	global $post;
    	global $product;
    	
    	if(empty($id)){
    		$id=$post->post_id;
    	}
    	
    	if(is_bool($permalink)) {
    		if($permalink){
    			$link = get_permalink( $id );
    		}
    	}else{
    		$link = $permalink;
    		$permalink = true;
    	}
    	
    	$target = "";		 
    	if($newwindow == 'true'){
    		$target="target='_blank' ";
    	}
    	
    	if(get_post_type( $id )=='product'){
    		$artikelnummer = $wpdb->get_var( "
    		SELECT COUNT(meta value) FROM $wpdb->postmeta
    		WHERE meta_key = '_sku'
    		AND post_id = $id
    		");
    
    	}
    	
    	if ( wc_product_sku_enabled() && ( $product->get_sku() || $product->is_type( 'variable' ) ) ) : ?>
    
    		<span style="font-size: 11px;">
    		<span class="sku_wrapper"><?php _e( 'SKU:', 'woocommerce' ); ?> <span class="sku" itemprop="sku"><?php echo ( $sku = $product->get_sku() ) ? $sku : __( 'N/A', 'woocommerce' ); ?></span></span></br >
    
    		<?php endif; ?>
    	
    		<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>
    		
    		</span>
    	<?php
    	
    }
    
    ?>
    • This reply was modified 8 years, 5 months ago by BierPlus.
    #665432

    Hi!


    @bierplus
    Thanks for sharing your solution :)

    Cheers!
    Yigit

    #665806

    thx @bierplus for sharing this! for products, only with this feature, the advanced editor is usable.
    for me it is not in my opportunity-range to adapt this for post-articles.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.