1

I'm looking to add a "News" section to my homepage, and want this to be a link in my admin left panel so I can add articles on the fly by clicking "Add Article" and providing the headline, publication date, publication logo, external URL, and a snippet from the article.

Initially, I thought of creating a custom post type, "News," which would give me this ability. But the articles are only intended to display on the homepage, and will take the user to the external source when they click on the image. The articles will not have their own page/post.

With that being said, is a custom post type the best approach, or is there something better out there?

1

A Custom Post seems entirely appropriate - in fact there is no logical alternative.

1

Yes, a combination of custom post types and custom fields. Since each post will technically be an external resource, you will want a custom field for the URL.

  • "Headline" will be the title
  • "Publication date" could be the post date, or a custom field
  • "Publication logo" could be the featured image
  • The "snippet" would go in the content (editor) box

This is the code for creating the custom post type:

function register_news_cpt() {

    $labels = array(
        'name'                => 'News', 
        'singular_name'       =>'News',
        'menu_name'           =>'News',
        'name_admin_bar'      =>'News',
        'parent_item_colon'   =>'Parent News Item:',
        'all_items'           =>'All News',
        'add_new_item'        =>'Add New Item',
        'add_new'             =>'Add New',
        'new_item'            =>'New Item',
        'edit_item'           =>'Edit Item',
        'update_item'         =>'Update Item',
        'view_item'           =>'View Item',
        'search_items'        =>'Search News',
        'not_found'           =>'Not found',
        'not_found_in_trash'  =>'Not found in Trash',
    );
    $args = array(
        'label'               =>'News',
        'description'         =>'News',
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'custom-fields', ),
        'taxonomies'          => array( 'category', 'post_tag' ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'menu_position'       => 5,
        'menu_icon'           => 'dashicons-media-document',
        'show_in_admin_bar'   => true,
        'show_in_nav_menus'   => true,
        'can_export'          => true,
        'has_archive'         => false,     
        'exclude_from_search' => true,
        'publicly_queryable'  => true,
        'capability_type'     => 'page',
    );
    register_post_type( 'news', $args );

}
add_action( 'init', 'register_news_cpt', 0 );
  • But what if I don't want there to be a page for the news items? As in, when i click Publish, I don't want there to be a anything that happens when I click "View Item" in the top admin navbar, nor do I want there to be a link to individual item pages, even if I'm not linking to them anywhere on the site. Is this possible? – andrw22 Oct 2 '15 at 21:23
  • 1
    See the answer here to disable single news item pages: wordpress.stackexchange.com/questions/128636/… – vancoder Oct 2 '15 at 21:35
  • The correct way to hide a custom post type is to set public & rewrite to false and show_ui to true. – TheDeadMedic Oct 3 '15 at 10:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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