Support » Plugin: Multiple content blocks » Fallback to top ancestor

  • Resolved redsundesign


    I liked candell’s post regarding displaying default content if the MCB field is empty. I’ve adapted this slightly and created a function to cut down on the amount of code in my page templates.

    function getMCBheadline()
    	$headlineblock = get_the_block('headline',array('type' => 'one-liner','apply_filters' => false));
    	$emptyheadline = "This is the default fall-back headline";
    	if  ($headlineblock != "") {
    		echo $headlineblock;
    	} else {
    		echo $emptyheadline;

    I’m creating a site where each main page has an addtional headline content block with a mission statement. Is there any way to get the content of the main page content block to show on child (or grandchildren) pages if their content block is empty rather than static default text using ‘get_top_ancestor’ or similar? Any help much appreciated.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Trendwerk


    Sure there is 🙂 It will probably be something like this, but I don’t know your exact circumstances so you’ll probably have to edit the code a little.

    function the_headline() {
      global $post;
      $fallback = "This is the default fallback when the current child AND the parent both dont have a headline";
      $headline = get_the_block('headline',array('type' => 'one-liner', 'apply_filters' => false));
      if(strlen($headline) == 0) $headline = get_post_meta($post->post_parent,'mcb-headline',true);
      if(strlen($headline) == 0) $headline = $fallback;
      echo $headline;

    Many, many thanks – that works perfectly.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fallback to top ancestor’ is closed to new replies.