Assigning two routes to the same category in Wordpress - wordpress

I wonder if it is possible to assign two routes to the same category. For example:
By accessing http://myblog.com/action or http://myblog.com/movie-action, leads me to the same category destination.
Thank you

i Think this plugin can handle this
http://wordpress.org/plugins/quick-pagepost-redirect-plugin/
it makes all kind of redirections in wordpress

One way to do this is to make all posts have both categories and then the links come up the same.
However, to do literally what you are asking, let's say you want to get to Category Action through Category Movie Action. See making categories in the Codex.
Create a .php file for the category you want to redirect. In this, make
category-movie-action.php
In this file, you can just paste the code
<?php
header( 'Location: http://myblog.com/action' ) ;
?>
And that should redirect anyone who goes to that particular category. If you need a more elegant solution I'm sure there are ways as well.

Related

Preventing search engines from indexing all posts

I'm working on a Wordpress site where I'm using the posts to create a list of tour dates for an entertainer. With ACF I have fields set up in a table and the client just enters a date, location, link to buy tickets, etc.
The table is all I need visitors to see. The actual post created by single.php is not going to be styled and should never be seen.
I want to prevent someone searching the artist and city and coming across the post.
Is there a plugin or a disallow I can put in the robot.txt file?
Any help is appreciated. Kinda funny in a time where everyone is trying to get noticed by search engines and I want to hide something from them!
Add the code below to your themes functions.php:
add_action('wp_head', 'your_prefix_noindex_nofollow');
function your_prefix_noindex_nofollow() {
if(is_single()){
echo '<meta name="robots" content="noindex,nofollow"/>';
}
}
You can also change "your_prefix" in the function name to whatever you like. It will work as is, but it's a good practice to use the same prefix in all your function names.

Appending query parameter to Woocommerce category URL

I'm trying to force display the list view in my Woocommerce store but I can't seem to get it working.
The theme has support for list view and you can force it by appending "?product_view=list" so a category URL becomes:
http://subliminalscience.com/product-category/icbch-hypnosis-certification/?product_view=list
Instead of the default one:
http://subliminalscience.com/product-category/icbch-hypnosis-certification/
I added this Rewrite Rule to my htaccess but it doesnt:
RewriteRule ^product-category(.*)$ http://subliminalscience.com/product-category$1?product_view=list
It seems Wordpress ignores this Rewrite rule. Any ideas?
I'm surprised this answer stands as the only one.
Making changes in .htaccess to force this sort of behaviour seems really unnecessary and obviously isn't useful for others trying to solve this issue, especially those users on nginx servers or on shared hosting without .htaccess access.
You should try to fix this in PHP using an action.
Looking at your question, I can tell that theme you have is checking for GET data in the URL bar, which is the ?key1=value1&key2=value2 part of an URL. GET is an HTTP method that you can read about here if you want to learn more.
You can actually set GET data in PHP, and you can safely put this into your functions.php file.
You will want to create a function that simply checks the current page, and if it's a product category page sets the GET data.
At the bottom of your functions.php, you'd want to add something like this:
<?php
//Force all category pages to list view.
add_action('woocommerce_before_main_content','force_category_list_view', 5);
function force_category_list_view(){
if(is_product_category()){
$_GET['product_view'] = 'list';
}
};
?>
I actually can't test this, but I think it'd work. Essentially, in the woocommerce template archive-product.php, the first action that runs is 'woocommerce_before_main_content'. What we're doing is calling our function, which checks the page is indeed a product category. If it is, it sets the GET variable as list, which is exactly what the URL is telling the page to do already.
Mainly this is just a better practise than altering your .htaccess, but someone determined could also override that GET data by changing the URL to read ?product_view=list&product_view=xyz I can't imagine this would be an issue in this instance, but in other instances it might be.

Page Template for every custom post type

I'm just new in wordpress, I just wanted to ask if it's a bad practice if I'll create page template for every custom post types?
I mean if I have CPT [custom post type] with different content, like my first CPT has images, my 2nd cpt has image and text, my last CPT, has slider, text and description.
Because I wanted to create page template for every type of CPT's I have. Is it a bad practice? Or are there efficient and effective ways to do such things?
Your answers are highly appreciated. Thanks!
It's better not to do that, not only because it's a server load, but also because you'll get crazy if you have an issue. Instead, use conditionals in the same page. You can read about it at WP Codex: Conditional Tags : Taxonomies and then pay attention to the is_tax and has_term tags.
This way, you can use is_tag or has_term depending on your approach, like this
if( has_term( 'jazz', 'genre' ) ) {
// do something
}
You can use taxonomy to deal with such problem. Use taxonomy to filter contents according to your requirements. Use register_taxonomy() to register a taxonomy for CPT.

Wordpress Post Sorting?

I to allow my users to sort the list of wordpress posts by Title, Date added, Comments, Rating etc. These will all be buttons or links at the top of the list (kinda like table view sorting)
However, I have no PHP experience and only know a few basics. How would I achieve this? I currently use the following line to sort my posts by name ASC:
<?php query_posts( $query_string . "&orderby=title&order=ASC" ); ?>
I was personally thinking of the following solution: orderby=VARIABLE1&order=VARIABLE2
Where VARIABLE1 would be set to title by default and VARIABLE2 would be set ASC by default. However I don't know if this is the best solution, and I know even less on how to achieve this.
Thanks for any future help!
Swen, attach ?orderby=title or ?orderby=date to the URLs of your buttons, WordPress will do the ordering itself.
One of the easiest way is just to use the Post Types Order plugin

Wordpress Plugin to Generate non-numeric slug / permalink for posts without titles? (1 post)

I've been looking for this all over, and simply cannot find it.
I have a blog that has no titles in its blog posts, but I'd like, for various usability reasons, to have the permalinks use the first few words from entries that do not have titles as the permalink slug.
ie, if the post on sample.com/blog is
Title: (no title)
Content: Ten Easy Ways to Lose Weight
The permalink could be sample.com/blog/ten-easy-ways-to-lose-weight.
Are there any plugins that do this? For the life of me, I cannot find one. (xposted to WP support, but no one is responding)
You could enter in titles, and then not display them in your view template.
I doubt there's anything like this already built for wordpress. To get your blog to do this, you have to write a plugin that does the following:
Generates the slug while checking
for uniqueness should you ever start
more than one entry with the same words
Processes URL requests to recognize slug permalinks and then updates the query step to locate the correct post in the database. This might involve a new db table of slugs (which would also help with the uniqueness issue)
In short, WP is designed to retrieve almost everything by keys, and to support slugs like this you'd have to create a new key type.
btw: if anything is retrieved by IDs (keys), it is technically not a permalink. so, wordpress probably fails in providing true permalinks.
ps: it's not that difficult to write an handler/dispatcher that would parse URL and takle out the unique permalink and then match it to the DB by the string (not by the key!).
something like:
$url=$_SERVER["REQUEST_URI"];
echo 'URL called: ',$url,'<br />';
$dispatchfile=$dispatcher->Dispatch($url);
if ($dispatchfile)
{
echo 'launching ',$dispatchfile,' inclusion<br />';
require($dispatchfile);
}
else
{
echo 'dispatcher failed to find module, will check physical file<br />';
if (file_exists($url)) echo 'dispatcher found physical file<br />';
else echo 'nada, throw 404!';
}
You can get a permalink redirect plugin from
http://scott.yang.id.au/code/permalink-redirect/
Works fine with WP2.71
It takes the Title and auto-creates a slug from that so you would have to manually enter the slug you wanted for each page if you have a Blank Title.
You should be able to hack Scott's PHP file (it is one page only) to look up the page code and select a portion of it to use as a slug though.
In addition, I solve incorrect page requests using a .htaccess rewrite file to bring up the index page upon an incorrect page request.
Download a copy of my rewrite file here
https://oulixes.com/htaccess_example.zip
Unzip the txt file and rename as .htaccess and upload into your root directory
Hope this helps!
Cheers,
Billy

Resources