Permalink structure when the website has two blogs - php

My website has two blogs. Imagine that their url are mydomain.com/blog1 and mydomain.com/blog2.
I'd like to have post url such as:
mydomain.com/blog1/sample-post-from-blog1
mydomain.com/blog2/sample-post-from-blog2
Posts from both blogs are under 'Post' Wordpress section and I think of differentiating them by tags or categories 'blog1' and 'blog2', although I'm not sure about what's the best practice.
So I'm kind of lost. Anyone has a clue about it?

Yes you can make it by making two separate custom post types for for both of the blogs. do not use default posts for your first blog.

I managed to do this:
I kept blog1 posts within default WP posts
For blog1 posts I defined a custom structure for permalinks: /blog/%postname%/
I created a custom post type for blog2 posts
To avoid the prefix '/blog/' to be applied to blog2 posts, I changed its 'with_front' property to 'false' (ref)
Using qTranslate Slug plugin, I set '/blog2-name/' as a slug for this new custom post type.

Related

how to use same slug for different post within same post type but have different category name in the permalink in wordpress

I want to use single category in the permalink and want to have multiple post having same slug.
Ex.
mysite.com/category-1/my-post
mysite.com/category-2/my-post
mysite.com/category-3/my-post
I know that wordpress does't allow multiple post with same slug but if there is any way to work around.
I have tried by making custom post type and adding it in the slug like
mysite.com/post-type-1/my-post
but still wordpress add -2 in the slug.
is there any other way or only way for making this happen ?
yes, you can add the custom slug of your post easily from your side bar of post page in WordPress dashboard permalink >>add your custom slug

WordPress url change, only for some categories

I have several categories in my WordPress blog. All posts are available through domain.tld/post-title. But now I need different urls for certain topics.
Example:
Blog > domain.tld/post-title
Category 1 > domain.tld/category-1/post-title
Category 2 > domain.tld/category-2/post-title
Category 3 > domain.tld/post-title
I would prefer not to use a plugin and set everything via custom-template.php or functions.php. I have seen a few solutions with str_replace, but unfortunately none of them worked properly for me.
I also use different layouts for different categories. So I could also use something inside the template file to change the urls.
This should be available through Wordpress' default functionality by using categories for each post & updating the permalinks.
If you already have the categories in place under "Posts -> Categories"
and have assigned them to each post then your next step would be setting how it is displayed in your Permalinks tab.
Here you can set site-wide URL structure. In your case it would use
/%category%/%postname%/
which would put the category before the title of the post each time the URL is spun up by Wordpress.

If URL x, load template, else single.php (on Wordpress)

I have custom posts that I want to be shown in a different template.
Right now I have custom posts on:
www.mywebsite.com/travel/post-name
All other (default) posts are on:
www.mywebsite.com/post-name
Basically, I'm trying to find a function.php code, that identifies URL and applies another template.
So, if path www.mywebsite.com/travel/post, then load post in traveltemplate.php
else, single.php
Any help would be appreciated.
P.S. this is not categories, so in_category category ID and category won't work.
I'm looking for a rough url identifier.
WordPress has a pretty sophisticated system to pick the “correct” template for specific pieces of content already, based on certain file naming patterns.
Check https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/, it explains how that looks for custom post types.
single posts of a custom post type will use single-{post_type}.php
and their archives will use archive-{post_type}.php

How to change the 'Projects' permalink to the Category of the post in Wordpress

I would like to change the permalinks for projects to use the specific post's parent category name. Is this possible? I have come across a few tutorials via Google, though none seem specific to this cause.
I am currently using the Wordpress Projects section for Events and a Menu (restaurant). I would like the URLs associated with the posts in each of those categories to be /events/post-name and /menu/post-name
From:
www.website.com/projects/post-name
To:
www.website.com/events/post-name
www.website.com/menu/post-name
The Yoast SEO plugin can help you for doing this kind of URL manipulation.
Also, it seems you need to create Custom Post Types for your different kinds of contents. In your case, you can create an Events post type and a Menu post type.
There are several plugins available to help you with Custom Post Types, for exemple: Custom Post Type UI, Toolset Types...
And this one: post-type-switcher can be useful if you want to transfer your existing content in a newly created Post Type.
Hope it will help

Wordpress Custom Permalinks for a Category whose Posts are automatically generated

I recently added a functionality to allow Twitter to create blog posts automatically whenever a new tweet is posted. As I'm using Wordpress Jetpack Publicize so I wanted the title of the posts to be the full tweet, that way it'll automatically update all my social channels.
As the permalink setting I'm using %postname% for all posts but in case of Twitter posts it gets way too long and creates issues with Backup and other things.
The Twitter post is assigned to a category Tweets so I want wordpress to set custom permalink for the same category posts. How can I do that?
You can see the twitter posts at my blog - http://robo.im/blog
I'm using Wordpress Plugin Twitter Tools to fetch the new Tweets
Just set the custom premalinks to /%category%/ here you can read what to do if posts have multiple categories.
But if not change urls for all categories, use custom post type instead of category, and follow one of many tutotrials how to change permalinks for that type.

Categories