Suport » Probleme și soluții » add_custom_background()

  • salut,

    incerc sa fac prima mea tema pentru wordpress si nu ma lamuresc cum functioneaza add_custom_background().

    trebuie sa adaug un stil pentru body sau ce trebuie sa fac ca setarile aplicate in panoul de administrare sa se reflecte asupare temei ?

    temporar am rezolvat cu:

    <body <?php
        $bgc = get_background_color();
        $bgi = get_background_image();
        if( !empty($bgc) ) echo "style = 'background:#$bgc;'";
        else if ( !empty($bgi) ) echo "style = 'background:url($bgi);'";
        ?> >

    dar nu stiu cum sa optin si optiunile care au fost setate pentru background (repeat,position, attachment).

    va rog sa ma ajutati.

Vizualizare 1 răspuns (din 1 în total)
  • Salut,
    am mai continuat de la ce ai inceput tu, dar acum am aflat si eu cum se face :)!

    function _get_custom_background() {
        $bgc = get_background_color();
        $bgi = get_background_image();
        $bgStyle='style="';
    	if (!empty($bgc)) {
    		$bgStyle.="background-color:$bgc;";
    		}
    	else {$bgStyle.="background-color:black;";}
        if (!empty($bgi)){
    		$bgStyle.="background-image:url('$bgi');background-repeat:no-repeat;";
    		}
    
    	$repeat = get_theme_mod( 'background_repeat', 'repeat' );
    	if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) ) {
    		$repeat = 'repeat';
    		}
    	else {
    		$repeat = " background-repeat: $repeat;";
    		}
    	$bgStyle.=$repeat;
    
    	$position = get_theme_mod( 'background_position_x', 'left' );
    	if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
    		$position = 'left';
    	$position = " background-position: top $position;";
    	$bgStyle.=$position;
    
    	$attachment = get_theme_mod( 'background_attachment', 'scroll' );
    	if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
    		$attachment = 'scroll';
    	$attachment = " background-attachment: $attachment;";
    	$bgStyle.=$attachment;
    	$bgStyle.='"';
    	return($bgStyle);
    	}
Vizualizare 1 răspuns (din 1 în total)
  • Subiectul „add_custom_background()” este închis pentru răspunsuri noi.