• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

PHP error in template

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › StudioPress Themes › Genesis Sample › PHP error in template

This topic is: resolved

Tagged: custom loop, genesis_loop, page template

  • This topic has 2 replies, 2 voices, and was last updated 10 months ago by ClintN.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • May 26, 2022 at 7:56 pm #505307
    ClintN
    Participant

    I am a weak PHP guy here.
    I want to upgrade my Genesis Sample theme to have a template for level one pages that dynamically displays the featured image + title of the child pages.

    I belive that there's something wrong with coding of my "if" statement that is throwing a critiacal error on the front end. Which is preventing me from knowing whether I have been on the right algorithm all along.

    Here's the template code:

    <?php
    /**
    * Template Name: Child GS
    *
    * @package Genesis Sample
    
    */
    
    get_header();
    ?>
    
    <?php
      $childPages = get_children( array(
        'post_parent' => get_the_ID(),
        'post_type' => 'page',
        'post_status' => 'publish',
        'orderby' => array(
          'menu_order' => 'ASC',
          'title' => 'ASC'
        )
      ));
    
    ?>
    //below has incorrect code
    
    <?php
      if (sizeof($childPages))
          echo '<div class="row">'
            foreach ($childPages as $page)
              echo '<div class="col-12 col-sm-6 mb-4">'
              echo '<a href="'get_page_link($page) echo '><img src="'get_the_post_thumbnail_url($page) echo' alt="'$page  ->post_title echo 'class="img-fluid mb-2"></a>'
                echo'<h2 class="text-center"><a href="'get_page_link($page) echo'">'$page->post_title echo'</a></h2>
              </div>'
            endforeach
      endif
          echo'</div>'
    
    ?>
    
    <?php get_footer(); ?>

    I have been looking at it for so long my pupils are quivering LOL

    Any advise on improving my coding & all solution would be greatly appreciated.

    May 27, 2022 at 2:24 am #505311
    Brad Dalton
    Participant

    A point in the right direction :

    1. No need for get_header or get_footer so remove them.

    2. Add genesis(); at the end of the file. This function loads the header and footer hooks including the markup.

    3. And remove the default genesis_loop and add it back with your function.

    	
    remove_action('genesis_loop', 'genesis_do_loop');
    add_action( 'genesis_loop', 'your_loop' );
    function your_loop() {
    // Your Code Here
    }
    

    You can then use WP_Query to create your own custom loop or genesis hooks to add and remove default hooks for different elements including featured image, content, titles etc.


    Tutorials for StudioPress Themes.

    May 27, 2022 at 4:50 am #505312
    ClintN
    Participant

    Awesome, I appreciate your guidance Brad!

    Thank you

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2023 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble