0

I'm trying to use categories to get all my posts (within a category-news) to go to the NEWS page on my site.

I've created the category 'news' with some posts and a 'category-news.php' file which is copied from category.php but I'm not sure how to get the posts to go to the news page.

I've tried following the steps from various forums from people who've tried to do something similar but I'm having no success copying them.

If i go to mypage.com/category/news I can see my posts there. But what I would like to acheive is to go to mypage.com/news and the categories would be there.

Does anyone know what further steps I have to take to get this working?

Thanks,

Ciaran

0

If you add RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L] to your .htaccess file (obviously replace your URL) this should remove category from the URL.

0

I'd suggest creating a custom page template or a custom post type for your "news" items.

For the first option, create a template based and include a query to get your "news" categories, and a Loop to display it.

$args = array('category_name' => 'news');
$news = new WP_Query($args);
if ($news->have_posts) {
  while ($news->have_posts) {
    $news->the_post();
    // display the content
  }
}

For the second option, register a post type for your news items. A very simple registration configuration, you will get a back end management screen like normal "Posts" have and an index on the front end. You can just add posts to the "News" type instead of trying to juggle categories.

// based on on code from the Codex for the Book type
function codex_custom_init() {
    $args = array( 'public' => true, 'label' => 'News' );
    register_post_type( 'news', $args );
}
add_action( 'init', 'codex_custom_init' );

The first option will work with any categorization you have already done. The second option would require you to convert your categorized posts to the new post type, but overall it is the more convenient (long term), efficient, and elegant solution.

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.