Menu Close

Change wordpress category order, PHP code, short code generation

WordPress Basic Category setting seems to be something good and very inconvenient. This is particularly true for people who have used other platforms said the tea story. I like the ability to select standard and drop-down formats, to display the number of posts in a category, or to express a layer (a sub-category is the right way to show the same thing as a single comment). However, it is fatal that you cannot arbitrarily change the order of the categories and that you cannot paste them anywhere on the site.

    How to change the wordpress category order

In particular, in the case of category order, it must be implemented because it is a necessary function due to various reasons.

In the WordPress admin screen, "plug-in" > "Add new" > "Category order and Taxonomy Terms Order" in the "keyword" column and install it and activate it.

Then a menu called "Taxonomy Order" is created at the bottom of the WordPress admin screen "POST" category, where you can change the order of categories by clicking and dragging with a really intuitive menu. Drag the category order as desired, then press the "Update" button to see the end of the operation, which will be applied immediately.

    WordPress Categories PHP Code

The disadvantage of not being able to paste anywhere on the site is the next problem, you can create a short code to fix it.

The category menu can be loaded via PHP and used to convert this PHP code into a short code. The basic PHP code for the category is shown below.

<?php the_widget('wp_widget_categories');=""?>

If you want to count the number of posts next to the category, you can add the "count" attribute. The variable value 0 is disabled, 1 is used.

<?php the_widget('wp_widget_categories',="" 'count="1');"?>

In addition, there is a "hierarchical" attribute that expresses the "dropdown" attribute and the hierarchy that represents the dropdown. To express all this, you have to jot down this way.

<?php the_widget('wp_widget_categories',="" 'count="1&dropdown=1&hierarchical=1');"?>

This is one of the most palatable. Just insert anywhere on the page you want.

    Create a wordpress category shortcut code

However, it is possible to import more easily or generate a short code on a page where PHP cannot be implemented. You can put the following code in the "functions.php. php" file by clicking on the "How to Short Code" category.

add_shortcode( 'shot_code_category', 'Category_Widget' );
function Category_Widget(){
    $widget = "WP_Widget_Categories";
    $instance = array(
    );
 
    ob_start();
    the_widget( $widget, $instance);
    $return_data = ob_get_clean();    
    return $return_data;
}

This is the basic form, and if you want to express the count, hierarchy, drop-down, and so on in this shortcut code, you can put the variable as shown below.

add_shortcode( 'shot_code_category', 'Category_Widget' );
function Category_Widget(){
    $widget = "WP_Widget_Categories";
    $instance = array(
    'count'    => '1',
    'hierarchical'     => '1',
    'dropdown'     => '1'
    );
 
    ob_start();
    the_widget( $widget, $instance);
    $return_data = ob_get_clean();    
    return $return_data;
}

You can also choose to taste, and unwanted attributes are erased.

Now just after "Add_shortcode", the name you specify will be the shortcut. As an example, you can use it as a shortcut code when you enter [Shot_code_category].

Comment (Information not required)

Posted in All, Wordpress

이메일 구독 - Email Subs

최선을 다해 직접 만든 콘텐츠만 공유합니다.
We share the best content we have created.