Tag Archives: custom post types

The first week of final project work…

I spent the weekend working off-and-on on my final project. When I sat down for my first intended work session, I felt immediately overwhelmed. I’ve never taken on a project like this one before. There were too many apps to be aware of: GitHub, MAMP, FileZilla, a tab of local WordPress testing, and a tab of the live site. Not to mention tab after tab of “how do I…” queries.

But as I spent more time on this project, I noticed more and more similarities with the work that I’m used to doing. For one thing, you can’t do it all in one sitting; you have to get up and move, to do something else, walk away and return. For another, there won’t just be one unfinished project; there will be many unfinished sections—the same way you move on to another paragraph when writing, even when you know you’ll have to come back later to tighten the language, add more context, or reassess the flow.

I’ve made some progress, but it was slow and buggy. I was elated to see that I have two functioning custom post types appearing on my life WordPress site. Then, I was immensely frustrated when I couldn’t figure out how to display those post types. I started working on my custom CSS as well, but didn’t get too far with it, because I thought I needed to add more content before I could really decide what properties I wanted certain classes and IDs to display. Back and forth, back and forth.

I’m coming to class with a lot of questions. But at least having questions means I’ve made some progress. Here are a few:

  • I copied the custom post type code from the Reading List example, but I can’t figure out how to add more than one meta box. When I tried simply duplicating the code, I threw an error on my test site: “invalid post type.” Undo, undo. Save. Walk away.
  • I have two custom post types built into my live site now (yay!): one for event posts, and another for job posts. I was hoping I would be able to use CSS to differentiate these posts visually, but when I refreshed my site, I couldn’t even figure out how to display these different posts! Research, research. Over my head. Save. Walk away.
  • I also have some wish list items that I imagine would be relatively do-able, but won’t focus on too much because I’m not sure they’re feasible with our timeline. But I’ll ask here, anyway: I would love a feature that would connect the data from my “event date” meta box to a calendar widget elsewhere on the site. That way, each event would appear both as an independent post, and as part of a collective calendar. Is this possible? And how hard would it be?

So many questions…

Long weekend of pizza and coding

This past week/weekend has taught me a lot about the world of coding — hours can fly by without you realizing it. However, that doesn’t necessarily mean that you’re completing numerous tasks…you could have gotten no where. For a few hours on Saturday, as I coded with a few classmates, that’s how I felt. That I had done so much work customizing my WordPress site, but was not getting the results I was hoping for. For example, I finally had success creating a custom post type (YAY!!), but after creating the meta boxes (following the guidelines of the Reading List example Greg showed us in class), the meta boxes weren’t working. The information was not being echoed correctly, or at all. That was infuriatingly frustrating. Today, it’s still not working. After putting that to the side, I worked on creating two other custom post types, had written all of the code and was ready to conquer these additional post types (TV Review & Restaurant Review). To no avail, I realized that WordPress doesn’t allow for multiple custom post types. Even after hours of Googling the answer, I haven’t been able to figure it out. Any help is appreciated!

Update on my final project site:

  • I’ve created three custom post types with meta boxes as plugins. They don’t work properly, but i’ve created them.
  • I’ve updated the CSS of the child theme as much as I could to my satisfaction for the layout/display of the site. I incorporated Google fonts, HEX colors, and updated the main menu navigation.

What’s left to do:

  • Continue working on getting the custom post types and meta boxes to work!
  • Adding two plugins: Instagram feed and Contact form
  • Inserting content

The next few days should be interesting. I am really hoping to be able to get the customizations I set out to do done and to successfully complete the project. Below are a few questions I have:

  • How do we add multiple custom post types?!
  • how do we get our meta boxes to echo the information we put in them?

Big shout out to Allie, Jaclyn, and Lucy for all their help this weekend!

APIs and Building My First Plugin

I had heard of APIs before taking this class, but this week’s readings and videos did a good job of breaking down this complex topic. The kitchen analogy used in the “What is an API?” video was helpful in terms of understanding how an API works as a messenger that communicates user requests and delivers responses back to the user. I recently booked a flight using the online travel service Kayak, and did not think about the fact that Kayak was using airline APIs to find me flights based on the parameters I defined. Kayak accesses the airline APIs and aggregates information from them based on user requests.

I also tried out one of the examples provided in the video about REST APIs. I typed the sample URL into my search bar and tweaked it for my hometown of Mendon, Massachusetts, which resulted in a page written in JSON that allowed me to access the GPS coordinates for my hometown (latitude: 42.1056525, longitude: -71.5522859). I then went to the main Google Maps site and entered these coordinates, and was taken directly to the center of my hometown on the map. I will have to do a bit more research on the topic of APIs in order to more fully understand how the concepts can be applied to WordPress. I imagine that APIs are probably used in a lot of plugins that access data from outside websites, such as those that pull in data from Twitter or Instagram feeds.

I spent this weekend working on the modifications for my WordPress site. As I mentioned in last week’s blog post, I was able to create my child theme and activate it on my local site, but I still have to play around with the fonts and colors of the site. I plan to do that towards the end of my project, once all of my other modifications are complete. One specific question I had regarding editing the styles.css file for my child theme is, how do you edit the fonts if your parent theme uses the Font Awesome toolkit? For example, I tried changing the font for my site header, but it is not working, and I’m thinking it’s due to the fact that my parent theme uses Font Awesome and thus has multiple CSS files. How do I change the fonts in this case? 

I also decided to tackle the custom post type modification by building a custom post type plugin. I was able to write the code for this plugin using these instructions, but ran into a lot of issues on the way to getting it to work. For example, when I tried to activate the plugin from my wp-admin panel on my local site, I kept getting the following error:

Parse error: syntax error, unexpected ” => array(‘ (T_CONSTANT_ENCAPSED_STRING), expecting ‘)’ in /Applications/MAMP/htdocs/finalproject/wp-content/plugins/therunningglover-run-post-plugin/therunningglover-run-post-plugin.php on line 18

I could not for the life of me figure out what the issue on line 18 was, and so back to Google I went. Luckily, the Stack Overflow gods were there to help out, and I figured out that I had forgotten a single quote (‘) on line 18 of my plugin code. I fixed the issue, refreshed the page, and the plugin was activated. However, the custom post type was still not appearing in my admin panel, and so I decided to go back to square one and rewrite my code using the steps listed on the WordPress codex. I got it to work within five minutes. Lesson learned — use the WordPress codex first. I now have a custom post type on my left admin panel called “Run.” Now I’m working on adding a custom metabox called “Run Details” with metadata (custom fields). One question I have is, how do I get my custom post type posts to show up on the home page of my site, rather than just under the Blog page?

This coming week, I want to download a plugin for Strava and see how I can use it to pull in information about my most recent running routes onto the sidebar of my site. When modifying the code of an existing plugin, do we need to create a “child plugin” (if that is such a thing)? I will also attempt to build a lightbox slideshow to display some of my photographs, but may end up using a plugin for this. I’m also planning to load some of my files using the FTP client later this week, to ensure everything is working correctly on my hosted site. I’m feeling a bit overwhelmed at all that I have to do in the next week-and-a-half, and am hoping that I can at least get three quarters of my proposed modifications done before the final project deadline.

Regarding GitHub, should I only be syncing files that I’m coding myself? For example, the plugins that I downloaded and added to my page from WP also synced to my final project GitHub repo. Should I remove the code for these plugins from my final project repo since these are not something I coded myself? If so, what is the best way to do this?