CustomPress-custom-post types: How can I get a sidebar- and background-image-choose-option?

Vinod is already on it – so here is the thing: I created a custom post type using CustomPress and now I would like to have this post type (as my default post types and as my default pages) the option in backend to choose a (or no) sidebar and a background image… Thanks in advance for your help!

  • aristath
    • Recruit

    Hello again @matthias, i hope you’re well today!

    I’m afraid I don’t quite understand what you mean….

    Do you mean you want to add new custom fields in your custom post type to allow selecting a background image and a sidebar???

    I’m also notifying @vinod Dalvi here since he’s already working on your issue as you mentioned.

    Please advise,

    Ari.

  • Vinod Dalvi
    • WP Unicorn

    Hi @matthias,

    I hope you are well today.

    Thank you for posting on the forum and sending me the theme as discussed on the live chat.

    Could you please try adding the following code in the functions.php file of your child theme to achieve it?

    add_action( 'add_meta_boxes', 'custom_meta_box_add' );
    function custom_meta_box_add(){
    add_meta_box( 'my-meta-box-id-6', 'Custom Page Background', 'add_background', 'stellenanzeigen', 'normal', 'high' );
    }

    Kind Regards,

    Vinod Dalvi

  • Matthias
    • The Incredible Code Injector

    that worked fine for the sidebar already – only the chosen background-image is not yet shown (you only see in backend that it is chosen while on front end there still is the “default-if-no-bg-image-is-chosen”-image)

  • Vinod Dalvi
    • WP Unicorn

    Hi @matthias,

    Thank you for your reply.

    To display the set background image for the stellenanzeigen post type in front end along with adding previously provided code in the functions.php file of your child theme add the footer.php file in to child theme by copying it from your parent theme vierra and edit it on line number 129 as following.

    Before Editing:

    <?php if($bg_image!="" && !is_single() ){ ?>

    After Editing:

    <?php if( $bg_image!="" && ( !is_single() || is_singular('stellenanzeigen') ) ){ ?>

    Best Regards,

    Vinod Dalvi

  • Ivan
    • HummingBird

    Hey Matthias,

    Hope you are well today!

    I believe you previous post type was named “stellenanzeigen”.

    If that is correct, can you please change in the code Vinod provided stellenanzeigen with you post type?

    If you have try it already, it will be helpful to post the code you are having problems with here.

    Thanks,

    Ivan

  • Matthias
    • The Incredible Code Injector

    thanks for answering, Ivan.

    My problem is as follows:

    add_action( 'add_meta_boxes', 'custom_meta_box_add' );
    function custom_meta_box_add(){
    add_meta_box( 'my-meta-box-id-6', 'Custom Page Background', 'add_background', 'stellenanzeigen', 'normal', 'high' );
    }

    – IIRC from the chat, I should add the following for the next type:

    add_action( 'add_meta_boxes', 'custom_meta_box_add' );
    function custom_meta_box_add(){
    add_meta_box( 'my-meta-box-id-7', 'Custom Page Background', 'add_background', 'arrangements', 'normal', 'high' );
    }

    But if I do so – I get “white screen” – so I cannot access anything anymore – neither front-end nor back-end… I have to delete CodeSnippets (the plugin I use to do all that) then via ftp to be able to access my site

  • aristath
    • Recruit

    Hello there @matthias, I hope you’re well today!

    The add_meta_box() function has a syntax like this:

    add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args );

    So in your case, according to what you posted above, you’re using it like this:

    id          => 'my-meta-box-id-7',
    'title => 'Custom Page Background',
    'callback' => 'add_background',
    'post_type' => 'arrangements',
    'context' => 'normal',
    'priority => 'high'

    • The id is ok.
    • title is ok.
    • callback has to be the name of a function that exists. Do you have a function called “add_background” in your installation? If not then this could trigger a fatal error.
    • context is ok.
    • priority is ok

    So I guess the only thing that could cause your white screen is the add_background argument if you don’t have a function named add_background on your site.

    I hope that helps!

    Cheers,

    Ari.

  • Matthias
    • The Incredible Code Injector

    Hi Ari,

    thanks for you answer. Two stupid questions about that:

    1st: Is there any place else than the function.php where this add_background could be?

    2nd: In case it is missing (at least it is in the function.php, hence the first question) – why did the first code for “stellenanzeigen” work, whereas the second does not?

    Thank you

    Matthias

  • Jack Kitterhing
    • Code Norris

    Hi there @matthias,

    Hope you’re well today and thanks for the additional information.

    Me and Ari have discussed this and if the first code block you posted worked, then the second should, as they both use the same callback, so it can’t be caused by that being incorrect.

    Could you send me the following please so we can take a closer look?

    – In the subject field add “Attn: Jack Kitterhing”

    – Link back to this thread

    – Include admin/network access

    – Include FTP

    – Include any relevant URLS for your site

    On the contact form, select “I have a different question“, this ensures it comes through and gets assigned to me.

    https://premium.wpmudev.org/contact/

    Thank you!

    Kind Regards

    Jack.

  • Jack Kitterhing
    • Code Norris

    Hi there @matthias,

    Hope you're well today and thanks for your patience here.

    I've been testing and everything functions wise looks good, though I did notice a difference within the setup of the custom post types (screenshot attached).

    Also I didn't see a functions.php in your active child theme, could you point to where you've added any custom code please?

    Thank you!

    Kind Regards

    Jack.

  • Patrick
    • Support Monkey

    @matthias & @jack Kitterhing & everyone else :slight_smile:

    Just to update this thread:

    This issue was resolved in live support just now.

    The problem @matthias had was that the additional function to output the metabox on the 2nd post-type had the same name as the 1st function. Result: WSOD Boom!

    Simply adding a new function in the same snippet with a new name resolved the issue, and all is well. :slight_smile:

    add_action( 'add_meta_boxes', 'custom_meta_box_add' );
    add_action( 'add_meta_boxes', 'custom_meta_box_add_2' );
    function custom_meta_box_add(){
    add_meta_box( 'my-meta-box-id-6', 'Custom Page Background', 'add_background', 'stellenanzeigen', 'normal', 'high' );
    }
    function custom_meta_box_add_2(){
    add_meta_box( 'my-meta-box-id-7', 'Custom Page Background', 'add_background', 'arrangements', 'normal', 'high' );
    }

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.