permalinks

Wordpress — permalink with custom post types

空扰寡人 提交于 2019-12-08 03:16:50
问题 I have created a custom post type as seen below, function transactions_register() { $args = array( 'label' => __('Transactions'), 'singular_label' => __('Transaction'), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array("slug" => "transaction"), 'supports' => array('title', 'editor', 'thumbnail') ); register_post_type( 'transaction' , $args ); } I have set my permalinks to be like this /%category/%postname however when I navigate to a

Permalink change each post update in wordpress

ε祈祈猫儿з 提交于 2019-12-07 13:30:27
I want to have a custom permalink for each new post in WordPress like: http://mysite.com/x5Kvy6 . function wp_unique_post_slug($col,$table='wp_posts'){ global $wpdb; $alphabet = array_merge( range(0, 9), range('a','z') ); $already_exists = true; do { $guidchr = array(); for ($i=0; $i<32; $i++) $guidchr[] = $alphabet[array_rand( $alphabet )]; $guid = sprintf( "%s", implode("", array_slice($guidchr, 0, 12, true)) ); // check that GUID is unique $already_exists = (boolean) $wpdb->get_var(" SELECT COUNT($col) as the_amount FROM $table WHERE $col = '$guid' "); } while (true == $already_exists);

Best Permalinking for Rails

随声附和 提交于 2019-12-07 11:19:48
问题 What do you think is the best way to create SEO friendly URLs (dynamically) in Rails? 回答1: Override the to_param method in your model classes so that the default numeric ID is replaced with a meaningful string. For example, this very question uses best-permalinking-for-rails in the URL. Ryan Bates has a Railscast on this topic. 回答2: ActiveSupport has a new method in Rails to aid this - String#parameterize. The relevant commit is here; the example given in the commit message is "Donald E.

How WordPress permalink system works?

ぐ巨炮叔叔 提交于 2019-12-07 06:10:35
问题 I am a php developer and i am currently developing a CMS/blog system. i want to add a permalink system like WordPress. i am curious about how WordPress parse permalink. For example, how to get data like id and post name from: example.com/id/123/post/example/ In short, I want a system to get id and post name from the url. I want to enable users to change the permalink structure like WordPress using tags like: id/%postid%/post/%postname%/ How do I get data in variables like $id and $post_name

Show only specific categories in permalinks for custom post type in WordPress

不问归期 提交于 2019-12-07 00:28:49
问题 I tried to ask this question in the Wordpress Devlopment network with no success, I'm trying to display only 3 specific categories in permalinks for custom-post-type categories. Right now the permalinks structure (that is the structure given by the theme i'm using and that i'm modifying through a child theme)is as follows: www.myfoodblog.com/recipes/the-post-title/ ^ ^ ^ root custom-post-type title some post are under 3 categories that i would like to display in permalinks which are

Have a WordPress page with same title as custom post type “front” slug

会有一股神秘感。 提交于 2019-12-06 17:28:50
问题 I have a custom post type djs and a custom taxonomy city with two terms: boston and nyc . So a DJ can either be tagged as Boston or NYC. DJ profiles (a single djs post) are located at /nyc-wedding-dj/joe-shmoe/ , for example, or for a Boston DJ, /boston-wedding-dj/jane-doe/ . In other words, the rewrite slug for that custom post type is set as %city%-wedding-dj . I have two regular pages called /boston-wedding-djs/ and /nyc-wedding-djs/ (note the plural DJs with an s ) where I use a custom

How do I use underscore in a wordpress permalink

微笑、不失礼 提交于 2019-12-06 12:25:11
问题 Wordpress converts my post title to a permalink which is great, the only thing is that I want underscores instead of hyphens, is there a quick solution? 回答1: Hunt down the following file: wp-includes/formatting.php Jump down to the sanitize_title_with_dashes function. You'll find this section of code inside: $title = strtolower($title); $title = preg_replace('/&.+?;/', '', $title); // kill entities $title = str_replace('.', '-', $title); $title = preg_replace('/[^%a-z0-9 _-]/', '', $title);

Random permalink key in wordpress

雨燕双飞 提交于 2019-12-06 11:52:41
问题 I want to have a custom permalink for each new post in WordPress like: http://mysite.com/x5Kvy6 (like bit.ly). I tried this little script, but it adds only 5-digit numbers to the post title in the permalink. function wp_unique_post_slug( $slug, $post_ID, $post_status, $post_type, $post_parent ) { if($slug!=""){ $random=rand(11111,99999); //I needed 5 digit random $slug .= "-" . $random; } return $slug; } How can I make a random key instead of the post title? I have not researched URL

Wordpress rewrite add base prefix to pages only

萝らか妹 提交于 2019-12-06 11:00:47
问题 I have a problem I've encountered when trying to finish a project. I have the current permalink structure set as /%postname%/ I made my own function on giving a prefix to posts only so my posts are rewritten as /{prefix}/%postname%/. My problem is that I want to change the permalink of the pages as I did with the posts so my pages will have a prefix like /{prefix}/%pagename%/. What I tried and didn't work: Re-declare the PAGES post type and set a rewrite slug. Tried adding a custom rewrite

First image only from photoset on indexpage, then all on permalinkpage

一个人想着一个人 提交于 2019-12-06 08:55:45
问题 Hello - I've been playing around with tumblr photosets and currently i'm using a masonry based theme. With the photosets, i wish to just show the first image of the photoset on the index page but on the permalink page i wish for all the images of the photoset to be shown. Thanks 回答1: You just need to adjust how you display it depending on if you're on the Index or Permalink. On the index, you'll loop through all of the photos and hide all of them except the first one via CSS. First, you'll