'group_60daba31d7ca8', 'title' => 'Inline Related Posts', 'fields' => array( array( 'key' => 'field_60daba6c5b50a', 'label' => '(1) Related Post Title', 'name' => '1_related_post_title', 'type' => 'text', 'instructions' => 'Add your link anchor text.', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', ), array( 'key' => 'field_60dabb1f5b50b', 'label' => '(1) Related Post URL', 'name' => '1_related_post_url', 'type' => 'url', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', ), array( 'key' => 'field_60dabb4c5b50c', 'label' => '(2) Related Post Title', 'name' => '2_related_post_title', 'type' => 'text', 'instructions' => 'Add your link anchor text.', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', ), array( 'key' => 'field_60dabb665b50d', 'label' => '(2) Related Post URL', 'name' => '2_related_post_url', 'type' => 'url', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', ), array( 'key' => 'field_60dabb775b50e', 'label' => '(3) Related Post Title', 'name' => '3_related_post_title', 'type' => 'text', 'instructions' => 'Add your link anchor text.', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', 'prepend' => '', 'append' => '', 'maxlength' => '', ), array( 'key' => 'field_60dabb905b50f', 'label' => '(3) Related Post URL', 'name' => '3_related_post_url', 'type' => 'url', 'instructions' => '', 'required' => 0, 'conditional_logic' => 0, 'wrapper' => array( 'width' => '', 'class' => '', 'id' => '', ), 'default_value' => '', 'placeholder' => '', ), ), 'location' => array( array( array( 'param' => 'post_type', 'operator' => '==', 'value' => 'post', ), ), ), 'menu_order' => 0, 'position' => 'normal', 'style' => 'default', 'label_placement' => 'left', 'instruction_placement' => 'label', 'hide_on_screen' => '', 'active' => true, 'description' => '', 'acfe_display_title' => '', 'acfe_autosync' => '', 'acfe_form' => 0, 'acfe_meta' => '', 'acfe_note' => '', )); endif; //function to add related links in the content function related_contents($contents) { $links = array(); $found_links = 0; for($i=1;$i<=3;$i++) { $this_title = get_field($i.'_related_post_title'); $this_url = get_field($i.'_related_post_url'); $link[$i] = '
'; if($this_title != NULL && $this_url != NULL ) { $found_links++; } } if($found_links==0) { return $contents; } $pattern = "/.*?<\/p>/m"; // Multiline $paragraph_count = preg_match_all($pattern,$contents); $para_count = 1; $para_third = floor($paragraph_count/3)-1; $paras = explode("
", $contents); $contents = ''; $link_count = 1; foreach($paras as $para) { if(($para_count % $para_third)==0) { $contents .= $para.$link[$link_count]; $link_count++; } else { $contents .= $para; } $para_count++; } $styles = ""; return $contents.$styles; } add_filter('the_content', 'related_contents'); ?>