Solved

Wordpress permalinks with custom pages and category titles

Posted on 2009-05-20
2
431 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Now that you've installed WordPress 2.9 (http://www.experts-exchange.com/articles/Web_Development/Blogs/WordPress/WordPress-2-9-What-to-Expect-When-Upgrading-to-WordPress-2-9.html?) on your site, you need to install some plugins to get the most out …
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 properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

728 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