• Resolved shadowsatthedoor

    (@shadowsatthedoor)


    Hello all,

    Quick question, is there a way to keep a post off the main page? Seems an odd request I know but I want to keep certain posts to a custom menu option (I know how to do that at least) but I’d like to keep a particular category off the main page feed.

    Thanks

Viewing 12 replies - 1 through 12 (of 12 total)
  • Theme Author Ben Sibley

    (@bensibley)

    Sure, that’s actually done pretty easily with the following function:

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

    You would add that to your child theme’s functions.php file (just create an empty file called functions.php if you don’t have one yet).

    The only part you need to edit is the number “251”. That is the ID of the category you want excluded. To find the ID of the category you want excluded, edit that category in your dashboard and you’ll find it in the URL.

    Thread Starter shadowsatthedoor

    (@shadowsatthedoor)

    Hi Ben,

    Well I’ve bitten the bullet and used the guide in Tracks support to create a child theme.

    However I’m editing all this from the editor within the WP Dashboard, so when trying to do the above I really don’t know where to put in a function.

    Likewise, with the following friendly advice: https://ww.wp.xz.cn/support/topic/move-written-by?replies=5

    I go down to the line you specify, and can’t seem to find it. Am I doing this wrong?

    Theme Author Ben Sibley

    (@bensibley)

    Okay let’s take it step-by-step. This is what you should be seeing when editing the child theme’s functions.php file: http://cl.ly/image/2y3r1H0r1t1x

    If there isn’t a functions.php file yet, you just need to create a file called functions.php and put it into the child theme folder.

    One word of caution, you will never break your site adding CSS, but with PHP a mistake can cause an error that will stop your site from loading. If you’re editing the PHP on your live site rather than on a local install, just be sure to have access to your serve at hand. This way, if you make a mistake in the functions.php file, you can access the file via FTP and remove the mistake. No harm done this way except the site not loading for the minute until you remove the error.

    Thread Starter shadowsatthedoor

    (@shadowsatthedoor)

    Thank-you.

    When I click on the editor and the child theme, I don’t get that. I originally got:

    /*
    Theme Name: Tracks Child
    Template: tracks
    */

    @import url(“../tracks/style.min.css”);

    /* =Theme customization starts here
    ————————————————————– */

    to which I then added a copy of the Tracks parent editor.

    I’d like to consider myself a little competent with computers and the like but I don’t know what the PHP file is. Nor would I know how to add one.

    Is this something that would need to be done outside of the WordPress editor (that I use in GoDaddy)

    thank-you again

    Thread Starter shadowsatthedoor

    (@shadowsatthedoor)

    Having a bit of an explore, if I click Edit CSS instead. It shows me an introduction wihh numbered lines on the side. I think this is what you originally meant. How how would I get the Tracks info in there?

    Thank-you

    Theme Author Ben Sibley

    (@bensibley)

    Okay sorry if I’m overwhelming you with this. I get confused between users sometimes – thought you had said you were comfortable editing PHP.

    Here is the final child theme that you need: click to download.

    To switch child themes: switch back to Tracks, delete the Tracks Child theme on your site, and upload the one linked to here.

    The only edit you’ll need to make is to change the “251” in the functions.php file to the ID of the category you want removed as explained earlier.

    Thread Starter shadowsatthedoor

    (@shadowsatthedoor)

    It wouldn’t let me install that link I downloaded as apparently I already had it.

    the functions.php file – is this the CSS Stylesheet editor? Do I need to copy the tracks info into this so that I cna edit it?

    🙂

    Theme Author Ben Sibley

    (@bensibley)

    If you delete the Tracks child theme currently installed on your site, you will be able to install the one I linked to above.

    I added the functions.php file there for you along with the edit to put the post author box above the widgets in the child theme, so it’s ready to go once activated.

    Thread Starter shadowsatthedoor

    (@shadowsatthedoor)

    Hi Ben, really appreciate your help and time.

    I uninstalled the theme, changed theme, downloaded, uplaoded and installed the child theme but nothing changed.

    I’ve done this again and again and I get the same result. I got a bit frustrated and found a plugin that has managed to keep the posts off the new page.

    I appreciate your help, maybe I’m just not good enough with WP :/

    Theme Author Ben Sibley

    (@bensibley)

    Okay I’m sorry it’s been such a hassle. Would you mind sharing the plugin you’re using to accomplish this?

    Thread Starter shadowsatthedoor

    (@shadowsatthedoor)

    No it’s my fault.

    Sure, least I can do. I’m using “Ultimate Category Excluder”

    Theme Author Ben Sibley

    (@bensibley)

    Okay, thank you for sharing!

    For anyone else who finds this thread, try the Ultimate Category Excluder plugin.

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘Keep posts off main page?’ is closed to new replies.