Home page display

Hi,
I was wondering if there is a way to display the Fundraisers on the Home page (like posts are displayed), and not on the menu.

Thanx,
Meital

  • Sajid

    Hello Meital,
    Hope you are doing good today :slight_smile:

    Since you are using the fundraisers on posts, that are meant to be displayed on home page out of the box.

    However, what we can do is, create a category called "Fundraisers" (or any other of your choice), add all these posts that have fundraisers in this category and exclude this category from home, blog page by using the following code snippet.

    function wpmudev_exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-1');
        }
    }
    add_action( 'pre_get_posts', 'wpmudev_exclude_category' );

    You can add this code in functions.php file of your child theme or use it as mu-plugin.

    If you go with mu-plugin route then, go to your /wp-content/ folder via FTP, and find the folder called "mu-plugins". If there is no folder with that name, then you'll want to create one. Then, create a file inside that folder, and give the file any name you like and paste the code in there.

    You don't need to activate that plugin, as it will be always be automatically activated. Please be sure to add a PHP start tag at the beginning of the code if you insert this code as a mu-plugin, like this:

    <?php

    Don't forget to replace the number 1 in code above with the ID number of your fundraiser category.

    You can find the ID of the category easily with the help of following plugin. It will add another column in Posts Categories called ID revealing the ID of corresponding category.

    Here is the link to plugin:
    https://wordpress.org/plugins/catch-ids/screenshots/

    Take care and have a nice day!

    Best Regards,
    Sajid

  • Sajid

    Hello Meital,
    Hope you are doing good today :slight_smile:

    Apologies for confusion. I thought you don't want to display some posts that have fundraisers in it.

    To display fundraisers on home page like WordPress default post. Please try using the following code instead.

    function wpmudev_display_funders_on_home_instead_of_posts( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'post_type', array( 'funder' ));
        }
    }
    add_action( 'pre_get_posts', 'wpmudev_display_funders_on_home_instead_of_posts' );
    
    function wpudev_append_fundraiser_panel_on_home_before_content( $content ){
    
    	if ( !is_home() ) return $content;
    
    	$fundraiser_panel = wdf_fundraiser_panel(false);
    
    	return $fundraiser_panel . $content;
    
    }
    add_action('the_content', 'wpudev_append_fundraiser_panel_on_home_before_content', 10 );
    add_action('the_excerpt', 'wpudev_append_fundraiser_panel_on_home_before_content', 10 );

    The code is different but instructions to use the code are same as posted in my last reply above.

    Hope that helps! But if you need further assistance, then please don't hesitate to post a reply :slight_smile:

    Best Regards,
    Sajid - WPMU DEV Support

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.