0

I'm currently working on creating my own templates with custom content to my wordpress site.

But I'm now struggling with getting the get_header(); function to work?

THIS IS WHAT I'M CALLING

<?php
/**
* Template Name: Register fangst
*
* @package WordPress
* @subpackage Salient
* @since Salient-child
*/
get_header(); ?>

<?php 
if ( ! is_user_logged_in() ) {
?>      
<h3>DU er ikke logget ind</h3>
<h4>så du kan ikke registre nogle registreringer</h4>
<a href="riverfisher/login">login her</a>

<?php   } else {
?>
<div class="wrapper">
<?php

global $wpdb;

require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');

if ( isset( $_POST['submit'] ) ){

$current_user = wp_get_current_user();
$time = trim ( $_POST['dato'] );
$attachment_id = media_handle_upload( 'file-upload', $_POST['billedeURL'] );
$attachment_url = wp_get_attachment_url($attachment_id);
$fiske_vaegt = $_POST['fiske_vaegt'];
$fiske_laengde = trim( $_POST['fiske_laengde'] );

$redskabsID = absint( $_POST['reg_redskabs_id'] );
$koenID = absint( $_POST['reg_koen_id'] ); 
$fiskID = absint( $_POST['reg_fisk_id'] );
$crID = absint( $_POST['reg_cr_id'] );
$laksID = absint( $_POST['reg_laks_id'] );  


$registrering = $wpdb->insert( 
$wpdb->prefix . 'registreringer',
    array(
        'reg_id'            => '',
        'dato'              => $time,
        'billedeURL'        => $attachment_url,
        'fiske_vaegt'       => $fiske_vaegt,
        'fiske_laengde'     => $fiske_laengde,
        'reg_user_id'       => $current_user->ID,
        'reg_redskabs_id'   => $redskabsID,
        'reg_koen_id'       => $koenID,
        'reg_fisk_id'       => $fiskID,
        'reg_cr_id'         => $crID,           
        'reg_laks_id'       => $laksID  
        ),
    array(
        '%d',
        '%s',
        '%s',
        '%f',
        '%d',
        '%d',
        '%d',
        '%d',
        '%d',
        '%d',
        '%d'
        )
    );

}
?>


<form method="post" enctype="multipart/form-data">
    <h3>Registering af din fangst</h3>
    <p><label><strong>længden</strong></label></p>
    <p><input type="number" name="fiske_laengde" id="fiske_laengde" />cm</p>
    <p><label><strong>vægten</strong></label></p>
    <p><input type="number" step="any" placeholder="vægt i kg f.eks. 12.3" name="fiske_vaegt" id="fiske_vaegt" />kg</p>
    <p><label><strong>Vælg billede:</strong></label></p>
    <p><input type="file" name="file-upload" id="file-upload"></p>
    <p><label><strong>dato</strong></label></p>
    <p><input type="date" name="dato" value="
<?php  
    $time = new DateTime;
    echo $time->format("d-m-Y");
?>"/>
    </p>
    <p><label><strong>Fangst udstyr</strong></label></p>
<?php 

    $redskab = $wpdb->get_results( "SELECT * FROM `wp_redskaber`" );

    foreach ( $redskab as $redskaber ) 
    {
        echo sprintf(
        '<label><input type="radio" name="reg_redskabs_id" value="%s"> %s</label><br>',
        esc_attr( $redskaber->redskabs_id),
        $redskaber->redskabs_navn
        );
    }
?> 
    <p><label><strong>Vælg fiskeart</strong></label></p>
<?php 

    $fisk = $wpdb->get_results( "SELECT * FROM `wp_fiskearter`" );

    foreach ( $fisk as $valgfisk ) 
    {
        echo sprintf(
        '<label><input type="radio" name="reg_fisk_id" value="%s"> %s</label><br>',
        esc_attr( $valgfisk->fisk_id),
        $valgfisk->fiske_navn
        );
    }
?> 

    <p><label><strong>Hvilket køn har fisken</strong></label></p>
<?php 

    $koen = $wpdb->get_results( "SELECT * FROM `wp_koen`" );

    foreach ( $koen as $valgkoen ) 
    {
        echo sprintf(
        '<label><input type="radio" name="reg_koen_id" value="%s"> %s</label><br>',
        esc_attr( $valgkoen->koen_id),
        $valgkoen->koen
        );
    }
?> 

    <p><label><strong>Catch / release</strong></label></p>
<?php 

    $cr = $wpdb->get_results( "SELECT * FROM `wp_cr`" );

    foreach ( $cr as $valgcr ) 
    {
        echo sprintf(
        '<label><input type="radio" name="reg_cr_id" value="%s"> %s</label><br>',
        esc_attr( $valgcr->cr_id),
        $valgcr->cr_type
        );
    }
?>  
            <p><label><strong>Vælg en lakseplads</strong></label></p>
            <select name="reg_laks_id">
                <option disabled selected value> -- Vælg en lakseplads -- 
</option>
<?php 

    $lakseplads = $wpdb->get_results( "SELECT * FROM `wp_laksepladser`" );

    foreach ( $lakseplads as $valgplads ) 
    {
        echo sprintf(
        '<option value="%s"> %s</option>',
        esc_attr( $valgplads->laksepladser_id),
        $valgplads->laksepladser_navn
        );
    }
?> 
    </select><br>
    <button type="submit" name="btnregister" class="button" >Submit</button>
    <input type="hidden" name="submit" value="submit" />
    <?php 
}
            echo "<pre>";
var_dump($_POST);
exit;
?>
    </form>
</div>
<?php get_footer();?>

As you can see it seems like something is going on but the little AJAX loading icon just keeps spinning for me ? Screenshot

Do you need to know anymore information to help me with this ?

EDIT:

page.php looks like this:

<?php 

get_header(); 
nectar_page_header($post->ID); 

//full page
$fp_options = nectar_get_full_page_options();
extract($fp_options);

?>

<?php get_footer(); ?>
  • Have you included the footer? Loading overlays are controlled by JS, which is probably output in the footer of your theme. – Jack Johansson Nov 8 '17 at 18:53
  • Yes i have unfortunately.. any other suggestions? :) – Mg10 Nov 8 '17 at 18:59
  • look what is the file page.php of the theme and you can probably use this as a base for your template/ – mmm Nov 8 '17 at 19:02
  • I've tried to copy it but it still keeps on loading that icon – Mg10 Nov 8 '17 at 19:08
0

If you remove the exit; call on line 176, does it load? It seems that the footer.php file will never be loaded because you are exiting before reaching that file.

  • Yes that did the trick. Oh I'm feeling so stupid. :) – Mg10 Nov 8 '17 at 20:22
1

First turn on debuggin by dropping the following code in your wp-config.php file

define( 'WP_DEBUG', true );
define( 'WP_DEBUG_DISPLAY', true );

and see if any errors or warning do get displayed.

Moreover it is a good practice to not close the php tag at he end of the file. Try that too.

  • Okay if I remove all my custom code the header and footer loads. BUT my custom code loads find without the header and footer? hmm I'm putting my code in the question – Mg10 Nov 8 '17 at 19:18
  • Removing that exit should have helped as mentioned above. – ghoul Nov 9 '17 at 4:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.