H1 si h2 diferit pe homepage si single

Mutex

Administrator
Administrator
Specialist SEO
Înscris
1 Mar 2018
Mesaje
222
Reputație
176
Puncte
43
Credite
294,4
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 );
}

Se mai poate face si prin (header.php):
<?php
if ( is_home() ) {
echo "Text ce apare pe homepage";
} else {
echo "Text ce apare pe restul paginilor";
}
?>

E putin mai complicat cu modificarea core-ului, dar e o alternativa. Mai jos aveti si fisierul general-template.php complet functional, doar in repuneti la fiecare update wordpress (uneori nu este necesar).
 

Atașamente

Utilizatori care vizioneaza acest subiect (Înregistrați: 0, Vizitatori: 1)

Sus