Solved

Wordpress permalinks with custom pages and category titles

Posted on 2009-05-20
2
424 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
Comment Utility
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
Comment Utility
Thank you very much. This solved my problem!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
WordPress has made it easy to create scalable sites based on their powerful CMS, but as great as WordPress is, there are some SEO issues that haven’t been addressed out of the box.  Fortunately these problems can be solved with a few plugins.  The f…
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now