• Any chance you could add a like/dislike to the admin posts screen?

    Something like this perhaps:

    
    add_filter( 'manage_post_posts_columns', function( $columns ) {
    	$new_column_name = 'like_dislike';
    
    	// Loop through and create a new array, adding in our column at the right spot.
    	foreach( $columns as $key => $value ) {
    		$new_columns[$key] = $value;
    
    		if( $key == 'comments' ) {
    			$new_columns[ $new_column_name ] = __( 'Like/Dislike', 'posts-like-dislike-admin-column' );
    		}
    	}
    
    	// Make sure our column has been added, if not, add it to the end.
    	if( ! array_key_exists( $new_column_name, $new_columns ) ) {
    			$new_columns[ $new_column_name ] = __( 'Like/Dislike', 'posts-like-dislike-admin-column' );
    	}
    
    	return $new_columns;
    } );
    
    add_action( 'manage_post_posts_custom_column', function( $column_key, $post_id ) {
    	$new_column_name = 'like_dislike';
    
    	if( $column_key == $new_column_name ) {
    		$pld_settings = get_option( 'pld_settings' );
    		$like_count = get_post_meta( $post_id, 'pld_like_count', true );
    		$dislike_count = get_post_meta( $post_id, 'pld_dislike_count', true );
    
    		if( $like_count > 0 ) {
    			$like_title = isset( $pld_settings['basic_settings']['like_hover_text']) ? esc_attr( $pld_settings['basic_settings']['like_hover_text'] ) : __( 'Like', PLD_TD );
    
    	       	switch( $pld_settings['design_settings']['template'] ) {
    	            case 'template-1':
    	                echo '<i class="dashicons dashicons-thumbs-up"></i>';
    	                break;
    	            case 'template-2':
    	                echo '<i class="dashicons dashicons-heart"></i>';
    	                break;
    	            case 'template-3':
    	                echo '<i class="dashicons dashicons-yes"></i>';
    	                break;
    	            case 'template-4':
    	                echo '<i class="dashicons dashicons-smiley"></i>';
    		        case 'custom':
    	            if ($pld_settings['design_settings']['like_icon'] != '') {
    		            echo '<img src="' . esc_url( $pld_settings['design_settings']['like_icon'] ) . '" alt="' . esc_attr( $like_title ) . '"/>';
    	            }
    	            break;
    	        }
    
    	        echo "<span class='pld-like-count-wrap pld-count-wrap'>$like_count</span>";
    	    }
    
    		if( $dislike_count > 0 ) {
    			$dislike_title = isset( $pld_settings['basic_settings']['dislike_hover_text']) ? esc_attr( $pld_settings['basic_settings']['dislike_hover_text'] ) : __( 'Dislike', PLD_TD );
    
    	       	switch( $pld_settings['design_settings']['template'] ) {
    	            case 'template-1':
    	                echo '<i class="dashicons dashicons-thumbs-down"></i>';
    	                break;
    	            case 'template-2':
    	                echo '<i class="dashicons dashicons-dismiss"></i>';
    	                break;
    	            case 'template-3':
    	                echo '<i class="dashicons dashicons-no"></i>';
    	                break;
    	            case 'template-4':
    	                echo '<i class="dashicons dashicons-dismiss"></i>';
    		        case 'custom':
    	            if ($pld_settings['design_settings']['like_icon'] != '') {
    		            echo '<img src="' . esc_url( $pld_settings['design_settings']['dislike_icon'] ) . '" alt="' . esc_attr( $dislike_title ) . '"/>';
    	            }
    	            break;
    	        }
    
    	        echo "<span class='pld-like-count-wrap pld-count-wrap'>$dislike_count</span>";
    	    }
    
    	}
    }, 10, 2);
    
  • The topic ‘Add column to admin posts list’ is closed to new replies.