Tutorial 2 headere si 2 footere (pentru h1 si h2)

Mutex

Active Member
Registered
Banned
[SHOWTOGROUPS=3,4,14]
Stiu ca multi vor sa aiba 2 headere si 2 footere asa ca m-am gandit sa pun un tutorial (nu pentru toata lumea) care sa va ajute sa faceti acest lucru. De exemplu, pe prima pagina vreti sa puneti h1 cu Animale de companie, insa va aparea si in articol si asta este destul de nasol pentru ca stim ca trebuie sa fie doar un h1.

Prima data facem 2 fisere numite headersingle si footersingle si copiem exact ce avem in header si footer in headersingle si footersingle. Acum umblam in headesingle si footersingle, punem h1 in headersingle si h2 in footersingle (eu asa procedez) si apoi in index.php modificam sa apara headersingle si footersingle. Ultima data, modificam in wp-includes/general-template.php si dupa functia header respectiv footer adaugam:

function get_headersingle( $name = null ) {
/**
* Fires before the header template file is loaded.
*
* The hook allows a specific header template file to be used in place of the
* default header template file. If your file is called header-new.php,
* you would specify the filename in the hook as get_header( 'new' ).
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string $name Name of the specific header file to use.
*/
do_action( 'get_headersingle', $name );

$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php";
}

$templates[] = 'headersingle.php';

locate_template( $templates, true );
}

function get_footersingle( $name = null ) {
/**
* Fires before the footer template file is loaded.
*
* The hook allows a specific footer template file to be used in place of the
* default footer template file. If your file is called footer-new.php,
* you would specify the filename in the hook as get_footer( 'new' ).
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string $name Name of the specific footer file to use.
*/
do_action( 'get_footersingle', $name );

$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "footer-{$name}.php";
}

$templates[] = 'footersingle.php';

locate_template( $templates, true );
}

Atentie: nu le dam replace, le adaugam dupa fiecare functie

Sau mai usor uitati exemplu:

<?php
/**
* General template tags that can go anywhere in a template.
*
* @package WordPress
* @subpackage Template
*/

/**
* Load header template.
*
* Includes the header template for a theme or if a name is specified then a
* specialised header will be included.
*
* For the parameter, if the file is called "header-special.php" then specify
* "special".
*
* @since 1.5.0
*
* @param string $name The name of the specialised header.
*/
function get_header( $name = null ) {
/**
* Fires before the header template file is loaded.
*
* The hook allows a specific header template file to be used in place of the
* default header template file. If your file is called header-new.php,
* you would specify the filename in the hook as get_header( 'new' ).
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string $name Name of the specific header file to use.
*/
do_action( 'get_header', $name );

$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php";
}

$templates[] = 'header.php';

locate_template( $templates, true );
}

function get_headersingle( $name = null ) {
/**
* Fires before the header template file is loaded.
*
* The hook allows a specific header template file to be used in place of the
* default header template file. If your file is called header-new.php,
* you would specify the filename in the hook as get_header( 'new' ).
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string $name Name of the specific header file to use.
*/
do_action( 'get_headersingle', $name );

$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "header-{$name}.php";
}

$templates[] = 'headersingle.php';

locate_template( $templates, true );
}

/**
* Load footer template.
*
* Includes the footer template for a theme or if a name is specified then a
* specialised footer will be included.
*
* For the parameter, if the file is called "footer-special.php" then specify
* "special".
*
* @since 1.5.0
*
* @param string $name The name of the specialised footer.
*/
function get_footer( $name = null ) {
/**
* Fires before the footer template file is loaded.
*
* The hook allows a specific footer template file to be used in place of the
* default footer template file. If your file is called footer-new.php,
* you would specify the filename in the hook as get_footer( 'new' ).
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string $name Name of the specific footer file to use.
*/
do_action( 'get_footer', $name );

$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "footer-{$name}.php";
}

$templates[] = 'footer.php';

locate_template( $templates, true );
}
function get_footersingle( $name = null ) {
/**
* Fires before the footer template file is loaded.
*
* The hook allows a specific footer template file to be used in place of the
* default footer template file. If your file is called footer-new.php,
* you would specify the filename in the hook as get_footer( 'new' ).
*
* @since 2.1.0
* @since 2.8.0 $name parameter added.
*
* @param string $name Name of the specific footer file to use.
*/
do_action( 'get_footersingle', $name );

$templates = array();
$name = (string) $name;
if ( '' !== $name ) {
$templates[] = "footer-{$name}.php";
}

$templates[] = 'footersingle.php';

locate_template( $templates, true );
}
[/SHOWTOGROUPS]
 
E ok varianta ta, insa dupa ce faci update la wp o sa pierzi modificarile acestea.
Cel mai simplu este sa va folositi de functions.php din folderul temei.
 
Din punctul meu de vedere metoda prezentata de tine e gresita.
Toate metodele care necesita modificarea core-ului wordpress ar trebui evitate.

In primul rand ca sa incarci alt header pe homepage putei inlocui direct in fisierele temei get_header(); cu get_header('numele-headerului-custom')

A doua metoda care nu necesita crearea unui header nou implica folosirea functiilor is_home sau is_front_page() (depinde cum e creata thema).
deschidem fisierul header.php si unde vrem sa modificam introducem urmatorul cod:
PHP:
<?php
if ( is_home() ) {
echo "Text ce apare pe homepage";
} else {
echo "Text ce apare pe restul paginilor";
}
?>


 
Ultima editare:
Loading...
Back
Sus