Create new blog default link categories

Thanks in advance for your help.

I created a theme for a single wordpress blog that allows the Editors to create a bookmark in the DIDYOUKNOW category and have it displayed on the sidebar. We were doing this by defining the link category id in functions.php and then referring to that when we call get_bookmarks (code below)

They now want to create more blogs using this same theme. Is there a good way to programmatically create new link categories and get their id's? Or I suppose i could rely on passing category_name into get_links. I've seen the blog default categories plugin, before I go about figuring it out, does something similar already exist for link categories? Or is there a smarter way to go about what I'm trying to achieve?

Thanks

/// functions.php
define(DIDYOUKNOW_ID, 8);

//sidebar.php
<?php
$dyk = get_bookmarks('category=' . DIDYOUKNOW_ID . '&limit=1&orderby=updated&order=DESC');

if(count($dyk)) : ?>
<div class="featbox">
<? foreach($dyk as $bkmrk) : ?>
<h3><?= $bkmrk->link_name; ?></h3>
<? if(strlen($bkmrk->link_image)) : ?>
<img src="<?= $bkmrk->link_image; ?>" alt="" /><? endif; ?>
<p>link_url; ?>" >Learn More</p>
<? endforeach; ?>
</div>
<? endif; ?>

  • synccreative
    • New Recruit

    Updating my own post, for anyone else curious.


    $new_link_categories = array("Awesome First Link Category", "More");

    foreach ( $new_link_categories as $cat_name )
    {
    $cat_name = trim($cat_name);
    $slug = sanitize_title($cat_name);
    if ( '' === $slug )
    continue;
    if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) {
    $cat_id = wp_insert_term( $cat_name, 'link_category' );
    }
    }

  • synccreative
    • New Recruit

    Updating my own post, for anyone else curious.


    $new_link_categories = array("Awesome First Link Category", "More");

    foreach ( $new_link_categories as $cat_name )
    {
    $cat_name = trim($cat_name);
    $slug = sanitize_title($cat_name);
    if ( '' === $slug )
    continue;
    if ( !$cat_id = is_term( $cat_name, 'link_category' ) ) {
    $cat_id = wp_insert_term( $cat_name, 'link_category' );
    }
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.