Wordpress - using same exact slug for different posts - wordpress

I looking for a a way to use the exact same slug url for a number of posts.
The url structure for my site is:
domain.com/category/slug
If I have created a post with a slug called "martin-nicolausson" in category "february" i would like to be able to create the same slug for the next month without wordpress adding a unique identifier at the end.
For a live example of what I mean;
http://www.5070.se/february/jacob-astrom-2

Short answer: you can't do it.
Long version: Since you can change what category a page/post is in, WP requires that the slug be unique across all pages/posts. Think of a category as an attribute of the post, as opposed to defining a namespace in which posts exist. Because the true namespace is global and flat, the slugs must be unique.

Related

Inserting a custom handler anywhere in a wordpress URL

I have some custom posts that I need to be able to list and link to at various points around a site.
They are case studies and I want to make them contextually relevant to services, which are currently just pages.
Ideally I want to be able to insert 'case-studies' into a URL, have it recognised and then either list relevant posts if there is nothing following it, or display the post based on the slug that follows case-studies.
EG:
/service1/case-studies - lists all case study posts relevant to service1
/service1/case-studies/blah displays the 'blah' case study post
In the above service1 is just a page. The URL might even be
/service1/subservice/case-studies
/service1/subservice/case-studies/blah
I'm thinking that relationships will handle the relevancy - so a case-studies listing will look up all case studies related to the slug preceding 'case-studies' in the url (so in these cases subservice or service1)
I've looked at wp-router (https://github.com/jbrinley/WP-Router) but I'm not sure how I can use the slugs preceding the case-studies marker to query for relevance.
Anyone had any luck with useful URL routing in Wordpress?

Possible to add two authors with same name, using Co-Authors Plus in WordPress?

Working on a large content base in WordPress, with the Co-Authors Plus plug-in installed. Several thousand authors. A new author needs to be added using the Guest Author functionality provided by the Co-Authors Plus plugin for WordPress, already enabled and successfully in use in our theme.
The new author wants his name spelled exactly as an existing author with the same name. Attempting to create the author record results in an error, wherein the plugin balks at the duplicate.
We only care about the Display Name - the slugs can be different, even have a number on the end. However, we can't use different fields than we already do, because we can't make the case for changing the front-end code just based on this error/case.
Has anyone had any luck with this, whether through a straightforward and sensible change in the plugin, a different method of data entry, or anything that's not too... "hackish"?
Been tinkering on and off for a couple days and arrived at a solution, although it's not ideal, that allows me to end up with multiple authors that have the same name.
In short, WordPress wants the new author's slug to be different than the first. Once that criterion is met and the record has been created, it appears I can do whatever I want with the Display Name on subsequent edits. The slug is generated automatically from the Display Name when the Guest Author record is created, so the trick is, well, to trick WordPress temporarily.
I followed these steps:
Choose a Display Name for the new author that will result in the creation of a slug you find acceptable. For example, if the original author's Display Name is John Smith (with a slug of john-smith), I used John Smith 2 as the Display Name for the new author.
Save the new author - in my example, the slug created upon saving was john-smith-2.
Now the new author can be edited - I changed the author's Display Name back to John Smith and saved without a problem or error.
Note that the slug, once created, cannot easily be changed, and in my case remained john-smith-2 - so make sure when you're creating the new author with the same name as an existing one that the slug that will be created from the temporary Display Name is something you can live with and, if possible, fits a pattern or system that you can use if you encounter this problem again in the future.

WordPress Categories vs URL Structure

I just launched my first WordPress site, and I'm confused by WordPress' Categories feature. I would like to set it up so that I have three URL structures:
Regular posts display # mysite.com/post-title
Posts in the category "World" display at mysite.com/world/post-title
Posts in the category "Issues" display at mysite.com/issues/post-title
It looks insanely simple, yet it isn't working for me. I went into Dashboard > Settings > Permalinks and entered "world" where it says Category base. I don't know how to add "Issues," because you can apparently only add one category here.
Then I went into Posts > Categories and created two categories - World and Issues. I then created a new post and assigned it to the category World. (I also entered a lower case slug version.) But the post displays at mysite.com/post-title, not mysite.com/world/post-title.
In summary, I would like to be able to 1) create a category (e.g. World), 2) create a new post and assign it to that category, and 3) see that category represented in the URL structure (e.g. mysite.com/world/post-title).
Can anyone tell me what I'm doing wrong?

getting posts from multiple categories in blog category template

I have 5 blog sections each representing a category. However, I would like to have a category called "all" that if checked would include the post in all 5 section without having to click every category.
I guess the only way to do this is to add something into the blog category template file to tell it to include the usual category posts as well as the "all" category.
now I think i've located where it queries the post:
if ( $wp_query->have_posts()) : while (have_posts()) : the_post();
but there is nothing identifying the current category id, except for a few things above for specifying the right title for the theme.
What would be the best way of achieving what I have explained?
You can interact with the wp_query object... the same way that you interact with query_posts()... it accepts the same arguments.
For either you can use Category Parameters as follows (from the wordpress codex: query_posts function reference)
Category Parameters
Show posts associated with certain categories.
cat (int) - use category id.
category_name (string) - use category
slug (NOT name).
category__and (array) - use category
id.
category__in (array) - use category
id.
category__not_in (array) - use
category id.
When it references $wp_query, the variables of the query have already been defined, you can set up your own query with any parameteres you want.

Wordpress Archive by Year "query_posts()" Problem

I created an Archive list (also this is my archive.php codes) on my blog and i want to show posts by years.
But when i use query_posts() function for excluding some categories and limit posts then it's showing all posts not by year.
For example this page is showing all posts not only posts in 2009 years.
So if i summarize this issue; i want to show archive list by year (when i enter /2009/ permalink)+exclude some categories and limit posts.
Thank you.
maybe when you use global variable, $query_string, it will help.
so you must use it like this
global $query_string;
query_posts($query_string . '&cat=-13,-4,-14,-171&posts_per_page=5&paged='. $paged);
as codex mention, here : query post,
Place a call to query_posts() in one of your Template files before The Loop begins. The wp_query object will generate a new SQL query using your parameters. When you do this, WordPress ignores the other parameters it receives via the URL (such as page number or category). If you want to preserve that information, you can use the $query_string global variable in the call to query_posts().

Resources