radgh
Forum Replies Created
-
Forum: Plugins
In reply to: [Post Types Order] No "Re-Order" linkSuddenly occured to me that I can find the link myself by temporarily making my post type show in the nav, lol.
I needed:
/wp-admin/edit.php?post_type=frontpage-panel&page=order-post-types-frontpage-panel
Update: Ok, get access denied once I change my custom post type back to: ‘show_in_menu’ => ‘frontpage’
That code makes my “Front Page Panels” appear under a menu called “Front Page”, which includes other options specifically for the front page.
Is there a way to get a link to manage that? Why is this plugin so difficult. Why is it passing ‘order-post-types-frontpage-panel’ instead of just ‘order-post-types’. Can’t the post type be derived from the &page= variable?.
This is too troubling.
Forum: Fixing WordPress
In reply to: Make blog posts appear as child of another pageI have solved the issue with the following code for now, but am not entirely pleased with the solution. Please let me know if you have a more elegant solution!
This code injects “/blog/” into the permalinks of all posts, and will allow /blog/ queries to point to the original post using some wp_query trickery. I would love to get the add_rewrite_rule functionality to work, as it would save an entire wp_query call, but I couldn’t get it to work.
// Adds behavior similar to an htaccess rewrite function blog_parent_rewrite_query() { global $wp_query; // Post type does not exist, query failed if ( $wp_query->post_count == 0 && !get_post_type() ) { $regexp = '/\/blog\/([^\/]*)\/?/'; $matches = array(); // Test if the URL has "/blog/" available and grab the remaining slug into $matches $is_blog_post = preg_match( $regexp, $_SERVER['REQUEST_URI'], $matches ); if ( $is_blog_post && isset($matches[1]) ) { $args = array( 'post_type' => 'post', 'name' => $matches[1], // magic 'posts_per_page' => 1 ); $wp_query = new WP_Query($args); } } } // Injects /blog/ into post permalinks when they are called function blog_parent_rewrite_permalink($permalink) { // Rewrite example.org/my-post/ -> example.org/blog/my-post/ if (get_post_type() == 'post') return str_replace( get_bloginfo('url'), get_bloginfo('url') . '/blog', $permalink ); return $permalink; } add_action( 'wp', 'blog_parent_rewrite_query' ); add_action( 'the_permalink', 'blog_parent_rewrite_permalink' ); // Remove canonical redirects, which will redirect /blog/my-post/ to /my-post/ automatically remove_filter('template_redirect', 'redirect_canonical');
Forum: Themes and Templates
In reply to: Allow duplicate taxonomy slugs?No I didn’t. I ended up using my own system using custom URL structure and completely abandoned the slug field for the category. I used “sanitize_title” on the title of the category to get a slug-formatted title. It’s all kind of hacky.
If you want to set up a custom URL structure you can look up the filter “query_vars”, the function “add_rewrite_rule” and finally you can access your wildcard using “get_query_var”. Brian Fegter pointed me in the right direction for this on stackexchange: https://wordpress.stackexchange.com/questions/62846/using-custom-dynamic-slug-for-a-page
Still, there may be a better way. Maybe one day when I have some more wordpress experience it will be worth making a plugin for this sort of category. But I don’t know.
Good luck.
Forum: Plugins
In reply to: [Quick Chat] [Plugin: Quick Chat] Nicknames instead of UsernamesWhy is there an option to let users change their username, but no nickname support? Isn’t that the point of nicknames? I say you should get rid of the option to let users change their chat name and instead support nicknames.
For now I’m using javascript to change the username field and hide it, very hacky. What’s a better way to change to show nicknames? Hopefully without having to use this “change username” box.
Forum: Fixing WordPress
In reply to: Get the index (or position) of a post within a custom post type?I never thought about using MySQL to do this. I guess that’s the best way, my current implementation is wasting several mysql requests and creating multiple wp_query objects. I could certainly do all of the heavy lifting with one (maybe two?) mysql queries. I did read somewhere not to worry about system resources for small scale projects (this website will have <50 visitors per day) but I can’t help but feel like it will take noticeably longer to load than the others.
I’ll look into this to optimize my script later. I’m not as comfortable with MySQL so that will be a journey of its own. Thanks though, I think I have what I need now. This link will be a great help, too.
Forum: Fixing WordPress
In reply to: Get the index (or position) of a post within a custom post type?“the paginated page that the post will be on” is exactly what I meant.
I think I am just going outside of what wordpress is made for, perhaps this isn’t the best way to lay it out to begin with.
For now I’ve got a pretty wasteful way of doing it. I get the ID of the active page, do a custom wp_query to get all posts, loop through them with a counter and when I find the active link, I return the counter.
Now with the counter I can do some math to find out what page it’s on. Since I have a full database stored I can also grab the next/prev/numbered pagination links too – since they won’t simply point to “press/page/2” but instead “press/article-name” directly.
If this were a large website this would be very hacky, but for now I’m ok with it.
But yeah, if there is a way to do this without pulling the entire custom post database to each request, I’d sure love to know. But I think that’s one of the features that is purposefully abstracted, as it would make things too complicated and there are better ways.
Forum: Fixing WordPress
In reply to: How do I allow a single page to be loaded with child-URLs?I received an answer on WordPress Stack Exchange: https://wordpress.stackexchange.com/questions/62846/using-custom-dynamic-slug-for-a-page
The trick is to use query_var filter and add_rewrite_rule, and then access the variable using get_query_var.
Forum: Fixing WordPress
In reply to: Adding new bbcodes, such as a "Did you know?" boxYeah I had edited my post, I guess you replied as I was doing that. I got it to work – I just had to change “Echo” to “Return”.
I assume this is because WordPress parses the data before it writes it, so making the tag use php to post text directly would throw it up before wordpress writes the actualy entry.
EDIT: Changing the float wasn’t the issue, although it doesn’t appear to work right now. I gotta make the stylesheet for this anyway, I can figure that out on my own. The code appears to be working fine.
Forum: Fixing WordPress
In reply to: Adding new bbcodes, such as a "Did you know?" boxEDIT: Nevermind, I was using echo instead of return. Derp!
I’ve got the bbcode working, so the following outputs what it should:
[didyouknow title=”Using Arrays” float=”right”]You can use arrays in programming![/didyouknow]
But this outputs to the top of my page (Where I declared the bbcode, which is in a PHP tag within my theme’s header.php).
function Didyouknow($params = array(), $content = null) { // Default parameters extract(shortcode_atts(array( 'title' => '', 'float' => 'none', ), $params)); // Formatting some variables if ($title != '') { $title = '<div class=\"didyouknow_title\">'.$title.'</div>'; } if ($float != "none") { $clear = '<div style="clear: both; font-size: 1px; display: hidden; width: 0px; height: 0px;">?</div>'; } // Display html echo "<div class=\"didyouknow\" float=\"{$float}\">{$title}<div class=\"didyouknow_description\">{$content}</div></div>{$clear}"; } add_shortcode('didyouknow', 'Didyouknow');
Forum: Fixing WordPress
In reply to: Adding new bbcodes, such as a "Did you know?" boxThe custom fields might work, but I kind of want to set up some styles for them to be displayed in the middle of my post. I think I found what I’m looking for here though: https://www.sitepoint.com/wordpress-shortcodes-tutorial/
Going to mess around with that and see what happens.