Have you ever had an element in your responsive website design which needed some padding, but you couldn’t add it because it broke the design? There’s a solution to that problem. Normally, the element in question will just add padding to the outside of itself, often expanding well beyond the space it is supposed to take up. But there is … Read More
tutorial - Category Archive
Passing a PHP Variable to Javascript in WordPress: The EASY Way
If you’ve made it here, odds are you’ve already been through the depths of the internet, full of “simple” tutorials talking about how easy it is to pass a variable in your PHP code to Javascript in WordPress. Maybe they even have simple, foolproof examples. The only thing is, they don’t work. WHY don’t they work? Who cares! They are … Read More
Dropdown List of Authors with Posts in Category – WordPress
While at first it may seem impossible, creating a dropdown list of all the authors with posts in a specific category is not actually all that difficult. This will work with custom taxonomies and custom post types as well, so it should suit the needs of just about anyone. Let’s get right to it! The Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
<form> <select onchange="window.open(this.options[this.selectedIndex].value,'_top')"> <option value="">Select by Author</option> <?php //Code to get a list of all authors with posts in this category, and then create a dropdown list of their names with links to their page $category = get_queried_object(); $taxonomy_name = 'custom_taxonomy_name_here'; //Change to reflect the name of your custom taxonomy $current_category = $category->slug; echo '<h1>' . $current_category . 'testing</h1>'; $author_array = array(); $args = array( 'posts_per_page' => -1, 'post_type' => 'custom_post_type_here', //Change to your custom post type 'tax_query' => array( array( 'taxonomy' => 'custom_taxonomy_name_here', //Change to reflect the name of your custom taxonomy 'field' => 'slug', 'terms' => $current_category ), ), 'orderby' => 'author', 'order' => 'ASC' ); $cat_posts = get_posts($args); foreach ($cat_posts as $cat_post) : if (!in_array($cat_post->post_author,$author_array)) { $author_array[] = $cat_post->post_author; } endforeach; foreach ($author_array as $author) : $auth = get_userdata($author)->display_name; $nicename = get_userdata($author)->user_nicename; echo '<option value="' . get_term_link( $category->slug, $taxonomy_name ) . '/' . $nicename . '">' . $auth . '</option>'; //creates the URL to our term, filtered by author endforeach; ?> </select> </form> |
There are … Read More
Get ID of Current Category – WordPress
Getting the ID of the current category in WordPress is actually quite simple. This will work in category archive pages or anywhere a category has been queried. We are going to use get_queried_object() to accomplish this task. The following script will get all the information about our queried object and put it in an array, $category. Then we are simply … Read More
Padding or Margin Only Affects First Line of Text – CSS
A common problem when formatting your website with CSS is that the first line of text in a paragraph, header, or link is affected by margin or padding while the remaining lines are not. It may even appear as though the first line is indented in some cases while none of the others are. Solution for padding or margin only … Read More
Authors Loop with Links to Pages – WordPress Tutorial
Creating the loop for a page that displays all of your authors in your WordPress website is something that’s not as straight-forward as you would think it would be. Additionally, actually linking to the author’s page is fairly tricky. So today I am going to show you how to do it. You can take the final code and put it … Read More
Dropdown Menu of All Terms in Custom Taxonomy – WordPress
Built-in to WordPress is a nifty function, wp_dropdown_categories, that is supposed to list all your categories in a drop-down menu and, with the right script, link directly to them. It even has an argument for using it with a custom taxonomy. The only thing is, it doesn’t work. It doesn’t produce the appropriate link. It appears to produce a link like /?cat=# … Read More
How to Open Layer By Itself in New Document – Photoshop
One thing that comes up a lot for me while building websites based off Photoshop designs, is that I need the ability to quickly and easily edit a layer by itself, as its own document, and then be able to export that file by itself as well. So how can we do that? I am using Photoshop CS5 though this … Read More
Custom Post Type – Title and Editor Not Displaying – WordPress Tip
If you’ve been working on adding a custom post type into your WordPress theme, only to fall flat when, inexplicably, the title and editor in the post edit screen have disappeared, have no fear! Here is the common cause. If you don’t add ‘supports’ => array( ) into your custom post type registration, then at the very least WordPress assumes … Read More
Display Posts with 2 or More Tags – WordPress Tutorial
It’s amazing how difficult it is to Google how to do this exact thing, but it’s so simple. But there are already pages linked into your WordPress site that will display all your posts that are tagged with multiple things. You just need to know how to link to it! Here is an example: Example: Link to all of my … Read More