Set the permalink to any domain in Wordpress - wordpress

Is this possible to achieve without too much effort or a plugin? It's simply to instantly redirect to a site I've made in my portfolio if the post doesn't have any content.
Note that I don't want a script in the actual post to redirect since I only use Wordpress as the backend and fetch all the data to be used by a JavaScript backbone app.
EDIT : Added some extra info in a comment

Short Answer: No. You cannot set your Post Permalink to an external asset without directly editing the database.
Long Answer: First off, you need to understand the purpose of the Permalink. It isn't just an arbitrary link to somewhere. It's reserved specifically for storing where that specific post lives within the context of your Wordpress installation.
Your post doesn't live on example.com. It has its own ID, and Wordpress has a specific spot set aside for it where it can be seen on YOUR domain. Leave it as such.
Instead, what you should be doing is employing the tools Wordpress gives you to achieve what you want. A Plugin doesn't exist for what you want because - quite frankly - it's a fairly trivial task when approached CORRECTLY and doesn't warrant the use of an external resource.
So what's the correct way?
Use a Custom Field. Name your Custom Field something like 'externalHref' and fill that in with your link to the website you want to point to in case there's no post content.
Then in whatever templates you're using to generate your posts, just check either for the existence of your Custom Field called 'externalHref' or check for the non-existence of Post Content. In either case, instead of generating a link using The Permalink you can simply build a link that points to wherever you need.

Related

WordPress URL structure logic, how two different urls point to same content?

I have noticed that after rewriting URL in a WordPress site, I can reach the same content using two URLs:
http://example.com/category/article-name-here/primary_key
as well as
http://example.com/category/article-name-here
Both of these URLs will point to exact same content. What is the exact logic behind it, is the article name is in itself unique?
I am creating a startup site which will have the same URL structure. But I cannot have same unique-article-name.
Check this article out:
http://codex.wordpress.org/Using_Permalinks
It says
In the Settings → Permalinks panel (Options → Permalinks before WordPress 2.5), you can choose one of the "common" structures or enter your own in the "Custom structure" field using the structure tags.
Wordpress uses something called a router, which is also part of many frameworks, particularly MVC frameworks, to determine what content to show based on the URL. For example, it might look up something in the database (e.g. old pages that have been renamed), then show the content based on that, or it might only look for a file on the server and then show a 404 page if it doesn't find it.
Basically, look into routing as it relates to PHP frameworks to see how that whole logic works.

Custom Post Type links not working

I'm wanting to make an employee page populated from a custom post type called "Employees". It lists http://www.domain.com/employees/joe/ as the permalink but the the actual page shows up as unavailable. Am I missing something on the taxonomy side?
Thanks in advance!
Answering it because I just figured it out, but after quite a bit of googling, nothing came up, so hopefully this helps somebody.
Reset the permalinks!
For some reason, if you create a custom post type after you initially set your permalink structure, it needs to be reset. Go to your settings/permalinks, set them to default, save, and then set them back how you want, save, and you're good to go.
The permalink structure needs resetting because this regenerates the rewrite rules within wordpress, allowing the different URL segment structures to be properly recognised and processed.
Wordpress rewriting works very well, but getting around it for custom post types, custom taxonomies etc. has added an extra set of needs to the system, which are slowly being improved. The custom rewrite system was added, and it's continued development is gradually making it easier to tackle issues like this.
In many cases, a custom taxonomy is the easiest way to go.

Add dynamic content to a WordPress Page

I want to know the most elegant/best practice way to do the following:
Let's say I have some PHP that returns a string (today's weather, for example). I want to be able to include the string within a WordPress Page, but not by using a plug-in to allow PHP within a Page.
So for example:
This is content of the page that is editable via WordPress pages.
Today's weather is THE_WEATHER. This bit is also editable, but as
an editor I can't edit the PHP that just told us what the weather
is, the developer does that.
What is the best practice way to do this (preferably without using plug-ins)?
Offhand, it sounds like you want to define a shortcode that lets you invoke the PHP function you're talking about and insert its result into a page/post. This pretty much means that you're writing either a (very simple) plugin or you're incorporating the shortcode definition into the functions.php file associated with a theme (which can be a simple child theme of the one you're using).
Which to do probably depends on whether or not you're likely to change themes (if it's just one site) or whether or not you need to do the same thing on different sites that can have different themes. If either is the case, then you should write it as a plugin; otherwise you can just make it part of your theme.
Consult the Codex to learn how to define shortcodes.

Wordpress, alternative single post template

For a project of mine I need to define an alternative template for single posts.
To be more specific I need each post to be displayed as usual when the website is browsed but I need to create different single pages reachable from different URL to create a sort of a mini-website for each post.
(I'm actually using the WooCommerce plugin and what I need to do is to create a mini-website for each product. This needs to be something "outside" from the main website, with a complete different graphic template and is going to be reachable through a QR-code).
Hope it makes a bit of sense.
Thanks for your advices and/or suggestions.
Angelo
I think the easiest way to do that is by registering a custom post type for the special posts that get this special "single.php" template. Then, you can simply write a new single template titled post-[custom post_type].php. Any post you register of this type will use that template.
OR...
If you don't actually need them to be posts, it's even easier if you publish them as pages. By default, pages let you assign a specific page template in the edit screen. So you could make any number of custom templates. Just make sure you add the special header:
/* Template Name: Custom Page */
...so WP knows it's a page template.

WP: writing an admin plugin for managing custom content

A client of mine has a site in wordpress, with one section being a directory of agents that each have different text and videos associated with them.
The client wants to be able to easily add/remove/change these agents from within the wordpress admin interface. There will be anywhere from 50-75 of these agents, so doing each page manually is not very attractive.
We currently have 3 agents added as posts, and i understand that we can store additional information inside the post itself, so that is not a problem. What we would like to create is a simpler way of managing those pages where the content cannot be changed by the maintainer, and the additional fields on the post are hard coded so there would be no room for user error.
What i am interested in is if anyone has done something similar in the past and can share their approach and experience, or if anyone can point me in the right direction as to how i can accomplish this and what i need to be aware of.
Thanks.
Yes, Custom Post Types are a perfect fit for your needs. Here are some links to articles explaining them:
http://justintadlock.com/archives/2010/04/29/custom-post-types-in-wordpress
http://www.wpbeginner.com/wp-tutorials/how-to-use-custom-post-types/
http://thinkvitamin.com/dev/create-your-first-wordpress-custom-post-type/
You can use a plugin like Custom Post Type UI or just add the register_post_type() calls to your theme's functions.php file:
http://wordpress.org/extend/plugins/custom-post-type-ui/
Then you can use a plugin like "Simple Fields" to add metaboxes to your Agent post type (although there are numerous plugins offering similar functionality; I'm building one myself!):
http://eskapism.se/code-playground/simple-fields/
Hope this helps...
Have you thought about using custom post types? You could create type called Agent and then each agent would be like a post. That way you could search for specific agents easily in the admin and then go in to the post for each agent to change their details.

Resources