• Resolved Robson.Pi

    (@robsonpi)


    Hi ??
    I love Tracks theme, but as I’m just “copy&paste” guy and I’m new to WordPress I can’t make WP work as I want.
    I searched through forums and tried all solutions that I’ve found, but it’s always not exactly that.

    I’d like WP to display lists of post on both main page and blog, but on main page posts from 1 selectec category only.

    First solution was setting static page in settings > reading.
    As I left “Front Page” empty and “Post page” as blog, post were showing on both pages.
    Then I tried to limit category on front page.
    I used different vertions of code:

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

    but it always effected not only front page, but blog too.

    So, I tried different way.
    In settings > reading “Front Page” as Home and “Post page” as blog.
    On static Home I used Post-in-page plugin (https://www.ads-software.com/plugins/posts-in-page/) pulling post from selected category.
    It’s working, but I lost list of post style used on blog page.

    At this point I’m not able to figure out what page should I use as Home templete.
    Or what content-type *.php file change and how to change, to make it work as template.

    Please, help.
    I’ve tried so many vertions of limiting main_query code that I don’t belive it will ever work.
    So, is possible in Tracks to make template for static page making it look like dynamic front page with posts?

    Thank you very much!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Robson.Pi

    (@robsonpi)

    While cooking dinner I thought about another vertion of filtering main loop and made solution mostly by accident ??
    It’s how it worked for me.

    In settings > reading “Front Page” as Home and “Post page” as blog.
    I used Post-in-page plugin (https://www.ads-software.com/plugins/posts-in-page/) pulling post from selected category on static Home.

    I also made plugin:

    <?php
    /*
    Plugin Name: Limit homepage to display a single Category
    */
    
    add_action('wp_head', 'iworks_only_one_category');
    function iworks_only_one_category()
    {
        if ( is_front_page() ) {
            global $wp_query;
            $wp_query->query('cat=10');
        }
    
    	if ( is_home() ) {
            global $wp_query;
            $wp_query->query('cat=-10');
        }
    }
    
    ?>

    After turning the plugin things work as I want.

    I tried this plugin earlier, but when settings > reading “Front Page” was set as empty (no page was set) it didn’t work.

    Theme Author Ben Sibley

    (@bensibley)

    Hey nice job! That Posts in Page plugin is really cool too, I’ll have to remember that.

    Do you still need any help with your customization?

    Thread Starter Robson.Pi

    (@robsonpi)

    Thanku you for you attantion!
    I’m OK for now ?? & marking topic as resolved.

    Dear Robson.Pi

    You are amazing diner-accident plugin maker.

    You are so brilliant, than you made exactly the same code, which I wrote 3 years ago.

    Shame of you.

    https://iworks.pl/2011/09/06/wyswietlanie-jednej-kategorii-wpisow-na-stronie-glownej/

    Marcin

    Thread Starter Robson.Pi

    (@robsonpi)

    I’m sorry Marcin – I didn’t mean that I wrote the plugin.
    As I wrote in first post I’m “copy&paste” guy.
    I wouldn’t be able to write something like that.

    I should write that “I used” code of your plugin.
    The truth is that I looked through so many posts about limiting the wp_query that I couldn’t find out who was the author of the code.

    Once againt – sorry for that.
    And thank You for great plugin.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Posts on both home page and blog page’ is closed to new replies.