Add new type from child theme


#1

I just purchased Moesia Pro and love it, you’ve done a great job at setting up a good foundation.

I want to add my own “Type” as you have with services, for example. Can this be done with a child theme? Could you give me a shove in the right direction?

Suppose I want to add a new type called “Foos” and I want to make a “Foos” widget and a “Foos” template… could you give me a push in the right direction? I don’t want to mess with your code so I’m trying to do all of this from within a child theme and I’m not sure where to begin.

Thanks! Love the work!


#2

Sure.

  • Add the custom post type you want in Types;
  • Copy the fp-services.php (or whatever widget you want to start from) file to yourchildtheme/widgets/fp-foo.php;
  • Open it up, find&replace services with foo (do it case sensitive).
  • Search for WP_Query, make sure the post_type is the actual plural name of your CPT;
  • If everything looks right, go ahead and add this to your child themes’s functions.php file and modify as needed:

function moesia_child_widgets() {
     register_widget( 'Moesia_Foo' );
}
add_action( 'widgets_init', 'moesia_child_widgets', 99 );

require get_stylesheet_directory() . "/widgets/fp-foo.php";

  • There is a chance that you’ll break stuff, don’t blame me if you do :slight_smile:

Not sure what template you want.
Let me know if it helps.


#3

Thank you very much! That’s a great place to start playing around. I’m not sure exactly what I want, either, I just want to make sure I handle things the right way so I don’t lose anything with updates.

You’ve been very helpful, thank you. (I’ll probably post another question or two in a bit)


#4

For anyone reading this later - I believe there’s a typo in Vlad’s text.

yourchildtheme/widgets/fp-foo.com should read

yourchildtheme/widgets/fp-foo.php

Pretty obvious but I don’t want a copy-paster to lose their mind.

:wink:


#5

Yeap, I’ve edited it. Thanks for noticing.