Site Overlay
Jose M Castaneda

New ideas and learning from them

One day while at work I was talking to one of the girls and brought up the fact that I love to mess around with WordPress. She was delighted to hear that because she was starting a personal blog for her child’s milestones.

She was on the lookout for a good theme for her newly created site. I told her that I was willing and happy to recommend some sites that offer some free ones as well as some that have premium themes. Now, I’ve never been a huge fan of paying in general so of course I was a little hesitant to name off a few but you are not just paying for the theme you are also paying for their support.

Recently on Twitter I’ve seen a lot of discussion about GPL. I do like it. I, unfortunately, haven’t read all of it. I have skimmed through some of the parts and I agree with what many of the people have to say about it but I am getting a little sidetracked. Although this does slightly pertain to what I have on my mind: themes. I know shocker, right?

I have messed with how WordPress handles some code and seeing how to create not only a useful theme but good ones as well. Since being able to assign myself tickets on Trac-WordPress Theme Review Team- I have been able to see how many other developers and theme-connoisseurs┬ácode their themes. This has given me plenty of ideas for my themes as well. Being able to test with somebody else’s code has been a great learning experience for me and has given me more confidence in applying for a job @Automattic as a theme developer/wrangler.

Yes, there are things that I still don’t feel as strong about but I am more than capable of finding the answer.

With that being said the current theme I am actually creating is for a baby milestone blog. What I am implementing is a custom post type called “milestones” which was a slight pain to get working at first. I finally managed to get the index page to work the way I intended since I was calling the wrong function to begin with.

What I was trying to use was

new wp_Query()

and not hooking to it to add the custom post type to the main query. In order to hook to the main query you have to use the hook:

add_action ( 'pre_get_posts' , 'add_custom_post_type_to_main', 9, 1 );
// Create the callback function
function add_custom_post_type_to_main( $query ) {
    if ( is_home() && $query->is_main_query() )
        $query->set( 'post_type',array( 'post', 'milestones' ) );
    return $query;
} 

in order for it to work properly. What it actually does it create the default

$query

and adds to it the newly created custom post type from the array of post_type.

The error I kept getting was a 404, meaning that there were no results being found when I would try to see more posts through the next_posts_link() and it kept giving me a minor headache. After some searching and reading I finally found the function I needed and now all is well. Next stage is getting all the images and the final look of the site down.

Published By:

Author: Jose

Born in El Salvador. Loves to read, write, draw, paint, build, test, typography, hike, photography, art, design, sewing, and many other things.

Some things were said, some code was broken. Proudly powered by WordPress