Solved

Wordpress permalinks with custom pages and category titles

Posted on 2009-05-20
2
428 Views
Last Modified: 2012-05-07
Hi everyone,

On my wordpress site (I am using this as a CMS) i have the following structure for a post:
http://www.domain.com/news/categorytitle/54/title-of-post/. I can get to the post without problems and I can get to the http://www.domain.com/news/ without problems.

How dit I do this:

I have created a few pages with custom query's in them to display all the posts that have a corresponding custom field. Example:

- news.php pagetemplate with in it a custom query that only displays posts where the custom field "news" is checked.
- Page named "news" which uses the news.php as a page template. This page has a permalink: http://www.domain.com/news/ which works great.

The problem is that I cannot get the url http://www.domain.com/news/categorytitle/ to work properly so I can list all news items in that specific category.
The url works but the page is displaying ALL the posts in the specific category and not just the posts within that category that also have the "news" field checked.

I have tried to use the code below in my functions.php file but it does not seem to work.

I hope someone can point me in the right direction?


function flush_rewrite_rules() 
{
   global $wp_rewrite;
   $wp_rewrite->flush_rules();
}
 
function add_rewrite_rules($wp_rewrite) 
{
  	$new_rules = array( 
    	'news/(.+?)/' => 'index.php?pagename=news&category_name='.$wp_rewrite->preg_index(1)
	);
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
 
/******
 Adding rewrite rules
******/
add_action('init', 'flush_rewrite_rules');
add_action('generate_rewrite_rules', 'add_rewrite_rules');

Open in new window

0
Comment
Question by:WouterN
2 Comments
 
LVL 1

Accepted Solution

by:
link2caro earned 500 total points
ID: 24506977
Hint:

You can create a page template for category-listing.php (this will be a subpage for news) with this method to define which category to list and just put it in your custom query for this category-listing.php:

$___category = split('%2F',$query_string);
echo $___category[count($___category)-1];

Use this to put in your custom query if you need to manage pagination :)
preg_match("@paged=+(.*?)&@", $query_string, $___page);
echo $___page[1];
0
 

Author Closing Comment

by:WouterN
ID: 31583565
Thank you very much. This solved my problem!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Who says nothing in life is free? WordPress.com is a freebie. WordPress.org's downloadable publishing platform is free. Heck, even WordPressMU is free. WordPress is an open source project, which means it can be used on any personal or commerc…
Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question