Skip to content

Instantly share code, notes, and snippets.

@pixeldevsio
Last active March 20, 2021 10:50
Show Gist options
  • Select an option

  • Save pixeldevsio/11b3f80e322eb0f10fdf1d6c9ce97d32 to your computer and use it in GitHub Desktop.

Select an option

Save pixeldevsio/11b3f80e322eb0f10fdf1d6c9ce97d32 to your computer and use it in GitHub Desktop.

Revisions

  1. pixeldevsio revised this gist Mar 20, 2021. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions pd_display_child_terms.php
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,10 @@ function pd_get_term_children($slug, $term_type = 'category'){

    // set up category by slug
    $category = get_term_by('slug', "{$slug}", "{$term_type}");

    // get out if no category
    if(!$category){return;}

    $cat_id = $category->term_id;

    //get the children as an array
  2. pixeldevsio revised this gist Mar 20, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pd_display_child_terms.php
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ function pd_get_term_children($slug, $term_type = 'category'){
    $cat_id = $category->term_id;

    //get the children as an array
    $cat_children = get_term_children( $cat_id, 'category');
    $cat_children = get_term_children( $cat_id, "{$term_type}");

    // call a display function to show the children
    return pd_display_term_children($cat_children, $term_type);
  3. pixeldevsio revised this gist Mar 20, 2021. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions pd_display_child_terms.php
    Original file line number Diff line number Diff line change
    @@ -10,12 +10,12 @@ function pd_get_term_children($slug, $term_type = 'category'){
    $cat_children = get_term_children( $cat_id, 'category');

    // call a display function to show the children
    return pd_display_cat_children($cat_children, $term_type);
    return pd_display_term_children($cat_children, $term_type);

    }

    // helper function to display term children
    function pd_display_cat_children($cat_children, $term_type){
    function pd_display_term_children($cat_children, $term_type){
    echo '<ul>';
    foreach ( $cat_children as $child ) {
    $term = get_term_by( 'id', $child, $term_type );
  4. pixeldevsio revised this gist Mar 20, 2021. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions pd_display_child_terms.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <?php
    // helper function to get children
    function pd_get_cat_children($slug, $term_type = 'category'){
    // helper function to get term children
    function pd_get_term_children($slug, $term_type = 'category'){

    // set up category by slug
    $category = get_term_by('slug', "{$slug}", "{$term_type}");
    @@ -25,4 +25,4 @@ function pd_display_cat_children($cat_children, $term_type){
    }

    //use case example
    pd_get_cat_children('parentcat', 'category');
    pd_get_term_children('parentcat', 'category');
  5. pixeldevsio revised this gist Mar 20, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pd_display_child_terms.php
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,4 @@ function pd_display_cat_children($cat_children, $term_type){
    }

    //use case example
    echo pd_get_cat_children('parentcat', 'category');
    pd_get_cat_children('parentcat', 'category');
  6. pixeldevsio revised this gist Mar 20, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pd_display_child_terms.php
    Original file line number Diff line number Diff line change
    @@ -16,7 +16,7 @@ function pd_get_cat_children($slug, $term_type = 'category'){

    // helper function to display term children
    function pd_display_cat_children($cat_children, $term_type){
    echo '<ul style="background: green">';
    echo '<ul>';
    foreach ( $cat_children as $child ) {
    $term = get_term_by( 'id', $child, $term_type );
    echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
  7. pixeldevsio renamed this gist Mar 20, 2021. 1 changed file with 0 additions and 0 deletions.
  8. pixeldevsio revised this gist Mar 20, 2021. No changes.
  9. pixeldevsio revised this gist Mar 20, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion pd_display_child_categories.php
    Original file line number Diff line number Diff line change
    @@ -25,4 +25,4 @@ function pd_display_cat_children($cat_children, $term_type){
    }

    //use case example
    echo pd_get_cat_children('parentcat');
    echo pd_get_cat_children('parentcat', 'category');
  10. pixeldevsio created this gist Mar 20, 2021.
    28 changes: 28 additions & 0 deletions pd_display_child_categories.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    <?php
    // helper function to get children
    function pd_get_cat_children($slug, $term_type = 'category'){

    // set up category by slug
    $category = get_term_by('slug', "{$slug}", "{$term_type}");
    $cat_id = $category->term_id;

    //get the children as an array
    $cat_children = get_term_children( $cat_id, 'category');

    // call a display function to show the children
    return pd_display_cat_children($cat_children, $term_type);

    }

    // helper function to display term children
    function pd_display_cat_children($cat_children, $term_type){
    echo '<ul style="background: green">';
    foreach ( $cat_children as $child ) {
    $term = get_term_by( 'id', $child, $term_type );
    echo '<li><a href="' . get_term_link( $child, $taxonomy_name ) . '">' . $term->name . '</a></li>';
    }
    echo '</ul>';
    }

    //use case example
    echo pd_get_cat_children('parentcat');