WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Child page custom field overriding partent custom fields (5 posts)

  1. vectyr
    Member
    Posted 12 months ago #

    Client wants to style each page of his site differently. Using this to display two custom fields.

    <?php $mymeta = get_post_meta($post->ID, 'background_image', true); if ($mymeta) {echo '<style type="text/css" media="screen">.background {background-image: url('.$mymeta.') !important;'; } ?>
    	<?php $mymeta = get_post_meta($post->ID, 'background_color', true); if ($mymeta) {echo 'background-color: #'.$mymeta.' !important;} </style>'; } ?>

    Problem is that I created a main page that displays child pages and on the main page, I think the first child custom fields are overriding the parent page's custom fields.

    Parent Page: http://sugareffect.com/dev/works/
    1st Child Page: http://sugareffect.com/dev/works/sugar-effect-into-sequence/

    Is there a way to display the custom fields for the current page only while ignoring the custom fields from the child pages?

  2. paulwpxp
    Font hero
    Posted 12 months ago #

    Are you sure there is really a parent's custom field ?

    Is your parent page a real page or archive ?

  3. vectyr
    Member
    Posted 12 months ago #

    You know, you're right, these ARE archive pages. I'm looking at the blog and post pages and particularly a custom post type archive page.

  4. vectyr
    Member
    Posted 11 months ago #

    Still need a solution though, any ideas?

  5. paulwpxp
    Font hero
    Posted 11 months ago #

    Conditionally fire your CSS from meta, like for example

    if ( 'works' == get_post_type() ) { <-your css from meta goes here-> }

    or

    if ( !is_post_type_archive() ) { <-your css from meta goes here-> }

Reply

You must log in to post.

About this Topic