Joey
Forum Replies Created
-
Forum: Hacks
In reply to: How to loop ads until end of pageForum: Hacks
In reply to: Display Thumbnail from Child Post in HierarchyHey,
Is this now working or am i misunderstanding the request? It looks like child thumbnails are being displayed on the linked page as you describe?
If it’s now working could you mark as resolved please ??
Thanks!
Forum: Hacks
In reply to: WordPress on GITHi,
Unsure if this is exactly what you’re looking for but we have a pretty simple setup when working on wordpress projects. We use composer as our dependency manager to pull in wordpress core (as these files do not change) and any other plugins/themes/packages we require for the project. We then create repositories for any custom plugins/themes we require and commit, push any changes we make.
Running “composer update” checks these repositories and updates them as required or you can cd into the theme/plugin and use git as normal.
A good introduction is here. You configure composer by telling it where everything is and then pull packages as required into the correct locations.
We currently use VVV to develop locally as well but don’t currently have automatic pushing of changes to live.
Hope that helps!
Forum: Hacks
In reply to: Login or sign up then register links on a pageHey,
So you’re after a membership plugin? A list of 30 reviewed membership plugins by a highly regarded author was published not that long ago which may be of use. Check it out here.
Hope that helps!
Forum: Hacks
In reply to: Need To Display Subcategories On Category Page and Hide Them From Main PageHey,
It’s great that you’re getting into some custom modifications ?? when dealing with wordpress the codex is your best friend and a little bit of php knowledge goes a LONG way. Also, be aware that if you are modifying code directly inside your theme any updates will overwrite your modifications. To avoid this look into creating a child theme which piggybacks off of your main theme adding features that you require but will not be touched when you update the parent theme.
1. So here get_categories is returning all of the categories defined by the $args array (just options for filtering your categories). In the codex it signifies that by setting a value of “hierarchical” to false, only parent categories will be returned. So you could change that array as follows:
$args=array(
‘orderby’ => ‘name’,
‘order’ => ‘ASC’,
‘exclude’ => ‘63,14,4,5,1’,
‘hierarchical’ => false,
)2. Here you could look at implementing a similar solution by using the ‘child_of’ OR ‘parent’ options and passing it the parent category id. This snippet should give you the parent id:
$category = get_category( get_query_var( ‘cat’ ) );
$cat_id = $category->cat_ID;and then your arguments would look something like this:
$args=array(
‘orderby’ => ‘name’,
‘order’ => ‘ASC’,
‘exclude’ => ‘63,14,4,5,1’,
‘parent’ => $cat_id,
)Otherwise another solution is outlined here that may be helpful.
Hope this gets you on your way! Good luck!
Forum: Plugins
In reply to: Is there a way to overwrite existing post?Very welcome. Can you mark the issue as resolved please ??
All the best
Forum: Plugins
In reply to: Random Post from Custom Post TypeI’m sorry I’m unsure how to replicate that setup on my end. It’s hard for me to create the code without the plugin installed :p
You can have a scan through the codex for those functions and see if anything comes close to what you need:
get_terms
wp_get_post_terms – may also be helpful.Good luck ??
Forum: Plugins
In reply to: Is there a way to overwrite existing post?Have added a function to clean the strings and change to lower case before the comparison. It still saves the new post as whatever the user enters however. For example if I create a post titles ‘Hello There!’, then another titled ‘hello!There!$%£$’ a new post titled ‘hello!There!$%£$’ will be created and the original moved to trash.
Obviously you can juggle the code around if this isn’t what you wanted and google will have the answer for any more preg_replace expressions you may need to add ??
<?php /* Plugin Name: Overwrite WordPress Posts if Title Already Used Description: Checks to see if post title has already been used and if so deletes the old post and creates a new one with the given data. Author: JPG Version: 1.0 */ // Filter used to access data before it is written to the database add_filter( 'wp_insert_post_data', 'overwrite_wordpress_post_if_title_exists', 99, 2 ); // Our function to delete the old post if there is a title clash (title must be identical) function overwrite_wordpress_post_if_title_exists( $data, $postarr ) { // Return if we aren't saving/updating a post if ( $data['post_status'] !== 'publish' ) { return $data; } $new_title = my_clean_string_function( $data['post_title'] ); $new_title = strtolower( $new_title ); // Return all existing posts $posts = get_posts( array( 'post_type' => 'post' ) ); // Loop through exisiting posts foreach ( $posts as $post ) { $old_title = my_clean_string_function( get_the_title( $post ) ); $old_title = strtolower( $old_title ); // If title already exists, delete the old post before we save the new one (change 'false' to 'true' to delete the post rather than trash it) if ( $old_title == $new_title && $post->ID != $postarr['ID'] ) { wp_delete_post( $post->ID, false ); $data['post_name'] = sanitize_title( $data['post_title'] ); } } return $data; } function my_clean_string_function( $string ) { return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars. } ?>
All the best
Forum: Plugins
In reply to: Random Post from Custom Post TypeSeries is a custom taxonomy so we want to look at get_terms().
I’ve tried to recreate a very simple version on my site and this code works for me, hopefully your setup is the same with that plugin or at least similar enough for you to have a decent starting point (quite tired so ignore the messy code!):
$terms = get_terms( 'series' ); $rand = array_rand( $terms ); $random_term = array(); $random_term[] = $terms[$rand]; foreach ( $random_term as $term ) { $term_link = get_term_link( $term ); // If there was an error, continue to the next term. if ( is_wp_error( $term_link ) ) { continue; } echo '<p><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></p>'; }
Hopefully that’ll get you started ?? good luck!
RegardsForum: Plugins
In reply to: Random Post from Custom Post TypeSo each episode is a post of post_type ‘anime’?
How are your series setup? You said before that they are a custom post type. If that is the case then you need to change anime to series (or whatever the name of that post type is) and it will return a random post of that type.
Apologies if I have misunderstood.
Forum: Plugins
In reply to: Random Post from Custom Post TypeHey,
how about dropping a little code like this somewhere (changing post_type to your custom post type)?
<?php $posts = get_posts( array( 'orderby' => 'rand', 'numberposts' => 1, 'post_type' => 'post' ) ); foreach($posts as $post) : ?> <p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">Random Post</a></p> <?php endforeach; ?>
Could go directly into sidebar.php for example but would be better to create a child theme and/or your own template so you don’t lose it on update ??
All this does is uses wordpress’ built in get_posts() function to return posts of the stated post type in a random order and numberposts => 1 ensures only one is returned. You can then use the_permalink() to create a link within your html.
Hope this helps!
Regards,
JoeyForum: Plugins
In reply to: I don't have a "Plug-In" option on my sidebar.There is a lot of information out there for this issue so may be worth having a look and trying to fix it following an example that closely mirrors your own.
One thing I’d suggest trying is disabling your plugins in case they are the cause. If you can’t do this in the admin area you can use ftp to rename your plugin file and create a new empty folder called plugins. If this fixes the issue you can then move the plugins across to this new folder and activate them one at a time to make sure none of them are the cause.
Good luck!
Regards, JoeyForum: Plugins
In reply to: Installed Plugin does not appear in DashboardHey,
I guess you have tried it both ways but just in case I would delete all instances of the plugin from the server and try reinstalling both ways (from within wordpress itself using the .zip and over ftp with the unzipped folder if that doesnt work)Forum: Plugins
In reply to: Show text if post by specific user IDWithin your template there are a couple of wordpress functions that should help you with this $author = get_the_author() will return the login name of the author of the post.
If you specifically needed the id of the author you could use $user = get_user_by( ‘login’, $author).
Then chuck in your conditional:if( $user->ID == 'my_user_id' ) { echo 'text to output goes here'; }
Hope that gives you a starting point ??
JoeyHey,
If you mean what I think you mean this can be done on pages and posts by changing the screen options. I implemented this recently on my own project following this tutorial
As it stands it doesn’t appear to be a feature available with the plugin at the moment.
Hope that helps,
Joey