WordPress.org

Ready to get started?Download WordPress

Forums

retrieve multiple pages and posts/ category for Home page, using query_posts? (3 posts)

  1. bleggate
    Member
    Posted 1 year ago #

    Hi

    I am wanting to feature on my home page only in an archive type feed, pages and posts (or a category) - using WordPress php and codex

    this is the code I have worked on to date for the functions.php file of my theme

    function child_before_loop () {
        global $query_string; 
    
        if( is_home() )
    $args = array(
      'post_type' => 'page',
      'post__in' => array(19)
      );
    $categoryvariable = $cat;
    $args = 'cat=10' . $categoryvariable . '&orderby=date&order=ASC';
    query_posts( $args );
    } 
    
    add_action('genesis_before_loop', 'child_before_loop');  
    
    add_filter( 'genesis_seo_title', 'child_header_title', 10, 3 );

    [Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum's parser.]

    I have also used this code below for categories only which works

    function child_before_loop () {
        global $query_string; 
    
        if( is_home() )
        query_posts($query_string . "&cat=10");
        } 
    
    add_action('genesis_before_loop', 'child_before_loop');  
    
    add_filter( 'genesis_seo_title', 'child_header_title', 10, 3 );

    [And again...]

    so the challenge is how to call cat10 posts and page id 19 at the same time.

    sure it must be simple but I am not seeing it.

    thanks

  2. bcworkz
    Member
    Posted 1 year ago #

    You'd think this was simple, but I don't think it is. The problem is the query parser wants to chain WHERE arguments together with ANDs. Your situation requires an OR. To effect this, you'd have to hook into the 'posts_where_paged' filter and add in the OR ID=9 clause (or whatever is actually the correct SQL form) there. But this must be only done for this query, not all of them, so your filter hook needs to determine this some how.

    If it's really just one page, it may be easier to output it before or after running the loop. If it needs to be injected between other posts, you might try adding an element in the right spot to the global $wp_query->posts property.

    I will allow that I'm just not seeing it either, but I do think this is what's happening.

  3. bleggate
    Member
    Posted 1 year ago #

    Thanks
    you got my brain ticking and what I did was use the pull certain categories in the functions.php

    function child_before_loop () {
    global $query_string;

    if( is_home() )
    query_posts($query_string . "&cat=10");
    }

    add_action('genesis_before_loop', 'child_before_loop');

    add_filter( 'genesis_seo_title', 'child_header_title', 10, 3 );

    then use Genesis simple hooks, and put in some content before the geneisis-before-loop hook to create what I wanted. Not pulling the page I wanted but linking to it which is what I wanted. see here

    <?php if(is_home( ) )
    {
    ?><p>insert images and text and any links you want here</p> <?php
    }
    ?>

    Thanks for your help

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags