• Resolved Lucas

    (@dechowmedia)


    Hey im currently developing my own theme.
    However I got a problem with my code in functions PHP.

    This is my code:

    function feature_post(){
    
    	if ( is_home() ){
    
    		 if ( have_posts() ) {
    			$featured = new WP_Query( 'posts_per_page=1' );
    			 while ( $featured->have_posts() ) : $featured->the_post(){ 
    
    			 	get_template_part( 'content', get_post_format() );
    
    			}endwhile;
    
    		}
    
    	add_action('feature_post','before_header');
    	}
    }

    And this is the error i am getting

    Parse error: syntax error, unexpected '{' in /Users/lucasdechow/Sites/the-damn-margin-blog/wp-content/themes/tdm/functions.php on line 184

    What have I done wrong?
    Im using the underscores

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter Lucas

    (@dechowmedia)

    I tried putting the hook code outside and correctly it worked.
    I don’t know what to do about the loop though, it still gives me this error:

    Parse error: syntax error, unexpected T_ENDWHILE in /Users/lucasdechow/Sites/the-damn-margin-blog/wp-content/themes/tdm/functions.php on line 188

    Hmm perhaps I use the endwhile wrongly…

    Thread Starter Lucas

    (@dechowmedia)

    I fixed it using this code instead.

    Just if anyone finds this thread and wonders how it is done this is how to do it:

    First we make a function (in functions.php) called featured which will create a custom WP_Query.

    function featured(){
    	$featured = new WP_Query( 'posts_per_page=1' );
    		if ( $featured->have_posts() ) { 
    
    		while ( $featured->have_posts() ) : $featured->the_post();
    
    			get_template_part( 'content', get_post_format() );
    
    		endwhile;
    		}
    }
    add_action('tdm_before_header','featured');

    Now I have created a hook using this function:

    function tdm_before_header() {
        do_action('tdm_before_header');
    }

    …and calls it from the theme using the function itself (note: excerpt) :

    ...
    <div id="page" class="hfeed site cf">
    	<?php tdm_before_header(); ?>
    	<header id="masthead" class="site-header" role="banner">
    ...
Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘[Theme: Underscores (_S) – custom build] PHP Error in my functions.php’ is closed to new replies.