Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Let me first explain what I am wanting to do...

I am wanting to add all my hundreds of website bookmarks that I have now in my browser, into wordpress for the following reasons.

  • Can search my bookmarks by category
  • Can search my bookmarks by tags
  • Can search my bookmarks by description and/or name
  • Can access my bookmarks from anywhere
  • Can add a description to all my bookmarks
  • Can add a screenshot image if I choose to (least important idea)
  • Will have a custom template for viewing the bookmarks which will look different from a regular blog post/list

And what I have done so far...

  • Created a new post type "Website Bookmarks" with the code below

functions.php

<?php
/*
*  Add custom post type
*  name: website_bookmarks
*/

function bookmark_post_type()
{
    // Set some labels for our bookmarks post type
    $bookmark_labels = array(
        'name' => _x('Website Bookmark', 'post type general name'),
        'singular_name' => _x('Websiteite Bookmark', 'post type singular name'),
        'add_new' => _x('Add New', 'Websiteite Bookmark'),
        'add_new_item' => __('Add New Website Bookmark'),
        'edit_item' => __('Edit Website Bookmark'),
        'new_item' => __('New Website Bookmark'),
        'all_items' => __('All Website Bookmarks'),
        'view_item' => __('View Website Bookmark'),
        'search_items' => __('Search Website Bookmarks'),'not_found' => __('No website Bookmarks found'),
        'not_found_in_trash' => __('No Website Bookmarks found in Trash'),
        'parent_item_colon' => '',
        'menu_name' => 'Website Bookmarks'
        );

    $bookmark_args = array(
        'labels' => $bookmark_labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'bookmark',
            'with_front' => false),
        'taxonomies' => array('post_tag', 'category'),
        'capability_type' => 'post',
        'has_archive' => true,
        'hierarchical' => false,
        'menu_position' => null,
        'can_export' => true,
        'supports' => array(
            'post-thumbnails',
            'thumbnail',
            'excerpt',
            'custom-fields',
            'editor',
            'title'
        )
    );

    register_post_type('website_bookmarks', $bookmark_args);
}

add_action('init', 'bookmark_post_type');

And then what I need help/ideas with...

This gives me a custom post type, so I can add my bookmarks as a post, and search them and all that good stuff, also lets me easily keep them out of my main blog loop, so I can keep them more private if I choose to. Also let's me easily create a template page just for the bookmarks.

Questions

  1. I would really like to be able to tag my bookmarks, many bookmarks will have more then 1 tag, example a site about PHP and MySQL and javascript, would be tagged with all 3 of those terms/tags. I know wordpress has tags built in already and I utilize it a lot on my current blog posts, should I add a NEW taxonomy ie. "bookmark_tags" because when a user views a tag page right now, it shows all my blog posts for that tag and I do not want a PHP tag page to show all my post's tageed with PHP and all my bookmarks tagged with PHP on the same page, so is the best method to create a new taxonomy called bookmark_tags?

  2. Same exact question as question number one (1), except in regards to Categories instead of tags?

  3. Any other Ideas or suggestions to improve my bookmarks section?


Thank you for any help

share|improve this question
    
Do you've found any plugins for importing bookmarks? –  Mamaduka Sep 25 '11 at 12:45
add comment

2 Answers 2

up vote 1 down vote accepted
+100

Here's a clean way to accomplish what you need.

  • Register custom post types (sans post_tags and categories)
  • Register taxonomies specific to your bookmarks
  • Create a post meta box for the bookmark options (sample included). You could add a nofollow checkbox option to the meta box.
  • Save post meta

Here's the whole shabang.

add_action('init', 'bookmark_post_type');
function bookmark_post_type()
{
    $labels = array(
        'name' => _x('Bookmark', 'post type general name'),
        'singular_name' => _x('Bookmark', 'post type singular name'),
        'add_new' => __('Add New'),
        'add_new_item' => __('Add New Bookmark'),
        'edit_item' => __('Edit Bookmark'),
        'new_item' => __('New Bookmark'),
        'all_items' => __('All Bookmarks'),
        'view_item' => __('View Bookmark'),
        'search_items' => __('Search Bookmarks'),'not_found' => __('No website Bookmarks found'),
        'not_found_in_trash' => __('No Bookmarks found in Trash'),
        'parent_item_colon' => '',
        'menu_name' => 'Bookmarks'
        );

    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'query_var' => true,
        'rewrite' => array(
            'slug' => 'bookmark',
            'with_front' => false),
        //'taxonomies' => array('post_tag', 'category'),
        'capability_type' => 'post',
        'has_archive' => true,
        'hierarchical' => false,
        'menu_position' => null,
        'can_export' => true,
        'supports' => array(
            'post-thumbnails',
            'thumbnail',
            'editor',
            'title'
        )
    );

    register_post_type('bookmarks', $args);

    $labels = array(
        'name' => _x( 'Bookmark Categories', 'taxonomy general name' ),
        'singular_name' => _x( 'Category', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Categories' ),
        'all_items' => __( 'All Categories' ),
        'parent_item' => __( 'Parent Category' ),
        'parent_item_colon' => __( 'Parent Category:' ),
        'edit_item' => __( 'Edit Category' ), 
        'update_item' => __( 'Update Category' ),
        'add_new_item' => __( 'Add New Category' ),
        'new_item_name' => __( 'New Genre Category' ),
        'menu_name' => __( 'Bookmark Categories' ),
    );  

    register_taxonomy('bookmark_categories',array('bookmarks'), array(
            'hierarchical' => true,
            'labels' => $labels,
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => array( 'slug' => 'bookmarks_categories' ),
    ));

    $labels = array(
        'name' => _x( 'Bookmark Tags', 'taxonomy general name' ),
        'singular_name' => _x( 'Tag', 'taxonomy singular name' ),
        'search_items' =>  __( 'Search Tags' ),
        'popular_items' => __( 'Popular Tags' ),
        'all_items' => __( 'All Tags' ),
        'parent_item' => null,
        'parent_item_colon' => null,
        'edit_item' => __( 'Edit Tag' ), 
        'update_item' => __( 'Update Tag' ),
        'add_new_item' => __( 'Add New Tag' ),
        'new_item_name' => __( 'New Tag Name' ),
        'separate_items_with_commas' => __( 'Separate tags with commas' ),
        'add_or_remove_items' => __( 'Add or remove tags' ),
        'choose_from_most_used' => __( 'Choose from the most used tags' ),
        'menu_name' => __( 'Bookmark Tags' ),
      ); 

    register_taxonomy('bookmark_tags','bookmarks',array(
        'hierarchical' => false,
        'labels' => $labels,
        'show_ui' => true,
        'update_count_callback' => '_update_post_term_count',
        'query_var' => true,
        'rewrite' => array( 'slug' => 'bookmark_tags' ),
    ));

}

//Create meta box
add_action('admin_init', 'bookmark_meta_boxes');
function bookmark_meta_boxes(){
    add_meta_box('bookmarks-meta', __('Bookmark Options'), 'bookmark_options', 'bookmarks', 'normal', 'high');
}

//Meta box form data
function bookmark_options(){
    global $post;
    $url = get_post_meta($post->ID, 'bookmark-url', true);

    echo "
    <div>
        <label for='bookmark-url'>URL</label>
        <input style='width:100%; padding:4px;' type='text' name='bookmark-url' value='$url' />
    </div>
    ";
}

//Save the form data
add_action('save_post', 'bookmark_save');
function bookmark_save($post_ID){
    //Do nonce checking here
    if('bookmarks' === $_REQUEST['post_type']){
        update_post_meta($post_ID, 'bookmark-url', esc_html($_REQUEST['bookmark-url']));
    }
}

To remove the bookmarks from the main loop, add this above the loop code:

query_posts('post_type=post');

If you want to control the archives and single contexts for your CPT, you will need to add two files called archive-bookmarks.php and single-bookmarks.php

By keeping 'publicly_queryable' as true in your post type, it allows searching of your bookmark posts.

You can use the_post_thumbnail function for your screenshot image.

I would use the content/editor area for your bookmark description.

share|improve this answer
    
thanks this is exactly what I ended up doing last night with 1 exception, I used $custom = get_post_custom($post->ID); $website_url = $custom["website_url"][0]; instead of what you have above $url = get_post_meta($post->ID, 'bookmark-url', true); is there any difference between two? I am choosing your answer as well, thank you –  jasondavis Sep 25 '11 at 19:33
    
@jasondavis get_post_custom() returns array of all custom fields for posts, while get_post_meta() returns custom field with the specific key –  Mamaduka Sep 25 '11 at 20:25
    
@jasondavis You can access the post meta however you choose. If you have one custom field, use get_post_meta, if you are storing more, use get_post_custom. :) Thanks Jason! –  Brian Fegter Sep 25 '11 at 21:50
add comment

I get the feeling that people are afraid of custom taxonomies which is a shame,

from the codex:

since version 2.3 of WordPress you've been able to create your own custom taxonomies, but these have been a rarely used feature of WordPress until Version 2.9.

For Both Bookmark tags and categories you should use custom taxonomies, it will make your search queries a lot easier and wont effect the rest of the site(post tags and categories).

And its free :)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.