Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Wordpress permalinks with custom pages and category titles

Posted on 2009-05-20
2
Medium Priority
?
438 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 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Did you use a default hosting installation of wordpress with the intention of it being your actual site?  Maybe you’ve installed it as a Blog to your current site and recently converted it to be the main site and do away with the old .htm pages.  An…
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 …
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…

610 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