Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Custom ID / classes to page sections

Open sschristina opened this issue 8 years ago • 17 comments

Hello,

Please see the below images. How can I add the custom classes to the sections and columns? Mine currently do not have this option.

(https://user-images.githubusercontent.com/39095137/39767233-2c316eaa-52de-11e8-83a8-acad9ad08881.png)

(https://user-images.githubusercontent.com/39095137/39767234-2c4b716a-52de-11e8-9b81-9036d1ffb0e7.png)

(https://user-images.githubusercontent.com/39095137/39767235-2c66438c-52de-11e8-80a9-f294008942e9.png)

Thanks!

sschristina avatar May 08 '18 15:05 sschristina

You must have some skills of php/css. Everything is documented here: http://manual.unyson.io/en/latest/extension/shortcodes/index.html#overwriting-shortcodes Please, hire someone if you don't have minimal knowledge of php/css. Shortly(for section shortcode) you must add a file in your themeYourTheme/framework-customizations/extensions/shortcodes/shortcodes/section/options.php

<?php 
$options = array(
	'unique_id'          => array(
		'type' => 'unique'
	),
	'section_name'       => array(
		'label' => __( 'Section Name', 'the-core' ),
		'desc'  => __( 'Enter a name (it is for internal use and will not appear on the front end)', 'the-core' ),
		'help'  => __( 'Use this option to name your sections. It will help you go through the structure a lot easier.', 'the-core' ),
		'type'  => 'text',
	),
	'class'              => array(
		'label' => __( 'Custom Class', 'the-core' ),
		'desc'  => __( 'Enter custom CSS class', 'the-core' ),
		'help'  => sprintf( __('You can use this class to further style this shortcode by adding your custom CSS in the %sCustom CSS%s area.', 'the-core' ), '<a target="_blank" href="'.$the_core_admin_url.'admin.php?page=fw-settings#fw-options-tab-custom_css_tab'.'">', '</a>' ),
		'type'  => 'text',
		'value' => '',
	),
);

Add a file to YourTheme\framework-customizations\extensions\shortcodes\shortcodes\section\views\view.php code:

<?php if ( ! defined( 'FW' ) ) {
	die( 'Forbidden' );
}

$bg_color = '';
if ( ! empty( $atts['background_color'] ) ) {
	$bg_color = 'background-color:' . $atts['background_color'] . ';';
}

$bg_image = '';
if ( ! empty( $atts['background_image'] ) && ! empty( $atts['background_image']['data']['icon'] ) ) {
	$bg_image = 'background-image:url(' . $atts['background_image']['data']['icon'] . ');';
}

$bg_video_data_attr    = '';
$section_extra_classes = '';
if ( ! empty( $atts['video'] ) ) {
	$filetype           = wp_check_filetype( $atts['video'] );
	$filetypes          = array( 'mp4' => 'mp4', 'ogv' => 'ogg', 'webm' => 'webm', 'jpg' => 'poster' );
	$filetype           = array_key_exists( (string) $filetype['ext'], $filetypes ) ? $filetypes[ $filetype['ext'] ] : 'video';
	$data_name_attr = version_compare( fw_ext('shortcodes')->manifest->get_version(), '1.3.9', '>=' ) ? 'data-background-options' : 'data-wallpaper-options';
	$bg_video_data_attr = $data_name_attr.'="' . fw_htmlspecialchars( json_encode( array( 'source' => array( $filetype => $atts['video'] ) ) ) ) . '"';
	$section_extra_classes .= ' background-video';
}

$section_style   = ( $bg_color || $bg_image ) ? 'style="' . esc_attr($bg_color . $bg_image) . '"' : '';
$container_class = ( isset( $atts['is_fullwidth'] ) && $atts['is_fullwidth'] ) ? 'fw-container-fluid' : 'fw-container';

if ( ! empty( $atts['class'] ) ) {
    $section_extra_classes .= " {$atts['class']}";
}

?>
<section class="fw-main-row <?php echo esc_attr($section_extra_classes) ?>" <?php echo $section_style; ?> <?php echo $bg_video_data_attr; ?>>
	<div class="<?php echo esc_attr($container_class); ?>">
		<?php echo do_shortcode( $content ); ?>
	</div>
</section>

ViorelEremia avatar May 09 '18 07:05 ViorelEremia

Hello,

Thank you, that works perfectly.

I just need the settings for each of the columns too? (see below) How would I get these working? I need to add classes to each column in the row?

(https://user-images.githubusercontent.com/39095137/39809073-b1702b7a-5378-11e8-8867-ad0b62fa6c6f.png)

(https://user-images.githubusercontent.com/39095137/39809075-b41d68c4-5378-11e8-931f-008134df2656.png)

sschristina avatar May 09 '18 10:05 sschristina

Hello,

Don't worry I have worked it out! - thanks again for your help!!

When I change the Section title - it still says 'Section' in the row display, how can I change that?

sschristina avatar May 09 '18 10:05 sschristina

Hello,

Sorry it doesn't seem to be registering the class - the option is there but when I inspect the element - the class isn't.

Here is the code I have put into the options.php of the column folder:

array( 'type' => 'unique' ), 'section_name' => array( 'label' => __( 'Section Name', 'the-core' ), 'desc' => __( 'Enter a name (it is for internal use and will not appear on the front end)', 'the-core' ), 'help' => __( 'Use this option to name your sections. It will help you go through the structure a lot easier.', 'the-core' ), 'type' => 'text', ), 'class' => array( 'label' => __( 'Custom Class', 'the-core' ), 'desc' => __( 'Enter custom CSS class', 'the-core' ), 'help' => sprintf( __('You can use this class to further style this shortcode by adding your custom CSS in the %sCustom CSS%s area.', 'the-core' ), '', '' ), 'type' => 'text', 'value' => '', ), ); Is this correct?

sschristina avatar May 09 '18 12:05 sschristina

Can anyone help with the above at all?

sschristina avatar May 14 '18 07:05 sschristina

Ok, I see you options.php.

array(
	array( 'type' => 'unique' ),
	'section_name' => array(
		'label' => __( 'Section Name', 'the-core' ),
		'desc'  => __( 'Enter a name (it is for internal use and will not appear on the front end)', 'the-core' ),
		'help'  => __( 'Use this option to name your sections. It will help you go through the structure a lot easier.', 'the-core' ),
		'type'  => 'text',
	),
	'class'        => array(
		'label' => __( 'Custom Class', 'the-core' ),
		'desc'  => __( 'Enter custom CSS class', 'the-core' ),
		'help'  => sprintf( __( 'You can use this class to further style this shortcode by adding your custom CSS in the %sCustom CSS%s area.', 'the-core' ), '', '' ),
		'type'  => 'text',
		'value' => '',
	)
);

Show your view.php: YourTheme\framework-customizations\extensions\shortcodes\shortcodes\column\views\view.php

ViorelEremia avatar May 14 '18 07:05 ViorelEremia

Ah there isn't a view in there - do I copy the row's view?

sschristina avatar May 14 '18 11:05 sschristina

Path in your theme: YourThemeName/framework-customizations/extensions/shortcodes/shortcodes/row/views/view.php View code:

<?php if ( ! defined( 'FW' ) ) {
	die( 'Forbidden' );
}

$row_class = ( $row_class = fw_ext( 'builder' )->get_config( 'grid.row.class' ) ) ? $row_class : 'fw-row';
$row_class .= ! empty( $atts['class'] ) ? ' ' . $atts['class'] : '';
?>
<div class="<?php echo esc_attr( $row_class ); ?>">
	<?php echo do_shortcode( $content ); ?>
</div>

ViorelEremia avatar May 14 '18 11:05 ViorelEremia

Great thank you - I have now added this in - but it still isn't recognising the column classes? I can type them into the edit box but it's not actually registering on the page?

sschristina avatar May 14 '18 11:05 sschristina

Is there anything else I can try?

sschristina avatar May 15 '18 08:05 sschristina

You paste to view.php in path YourThemeName/framework-customizations/extensions/shortcodes/shortcodes/row/views/view.php? I was wrong you must paste it in YourThemeName/framework-customizations/extensions/shortcodes/shortcodes/column/views/view.php Where did you paste it?

ViorelEremia avatar May 15 '18 08:05 ViorelEremia

Hello,

I have done this and can now see the classes - however all the columns on the page have now gone on top of each other? My row of 4 columns, now appears to be 4 rows for some reason?

sschristina avatar May 15 '18 08:05 sschristina

What code do you have in view.php? You must check my code before pasting it into production. I write it on the fly.

<?php if ( ! defined( 'FW' ) ) {
	die( 'Forbidden' );
}

$class = fw_ext_builder_get_item_width( 'page-builder', $atts['width'] . '/frontend_class' );
$class .= ! empty( $atts['class'] ) ? ' ' . $atts['class'] : '';
?>
<div class="<?php echo esc_attr( $class ); ?>">
	<?php echo do_shortcode( $content ); ?>
</div>

ViorelEremia avatar May 15 '18 09:05 ViorelEremia

That seems to have fixed it! Thanks, I really appreciate that.

I just need to get the Section names to display on the rows, I can see the input box, just need it to display on the page?

screenshot 2018-05-15 10 32 53

sschristina avatar May 15 '18 09:05 sschristina

to display section name in the row I think you cant because you can have more rows in the section but to show section name in the section div you can do in the same way like with the row add a view in YourThemeName/framework-customizations/extensions/shortcodes/shortcodes/section/views/view.php with code:

<?php if ( ! defined( 'FW' ) ) {
	die( 'Forbidden' );
}

$bg_color = '';
if ( ! empty( $atts['background_color'] ) ) {
	$bg_color = 'background-color:' . $atts['background_color'] . ';';
}

$bg_image = '';
if ( ! empty( $atts['background_image'] ) && ! empty( $atts['background_image']['data']['icon'] ) ) {
	$bg_image = 'background-image:url(' . $atts['background_image']['data']['icon'] . ');';
}

$bg_video_data_attr    = '';
$section_extra_classes = '';
if ( ! empty( $atts['video'] ) ) {
	$filetype           = wp_check_filetype( $atts['video'] );
	$filetypes          = array( 'mp4' => 'mp4', 'ogv' => 'ogg', 'webm' => 'webm', 'jpg' => 'poster' );
	$filetype           = array_key_exists( (string) $filetype['ext'], $filetypes ) ? $filetypes[ $filetype['ext'] ] : 'video';
	$data_name_attr = version_compare( fw_ext('shortcodes')->manifest->get_version(), '1.3.9', '>=' ) ? 'data-background-options' : 'data-wallpaper-options';
	$bg_video_data_attr = $data_name_attr.'="' . fw_htmlspecialchars( json_encode( array( 'source' => array( $filetype => $atts['video'] ) ) ) ) . '"';
	$section_extra_classes .= ' background-video';
}

$section_style   = ( $bg_color || $bg_image ) ? 'style="' . esc_attr($bg_color . $bg_image) . '"' : '';
$container_class = ( isset( $atts['is_fullwidth'] ) && $atts['is_fullwidth'] ) ? 'fw-container-fluid' : 'fw-container';
?>
<section class="fw-main-row <?php echo esc_attr($section_extra_classes) ?>" <?php echo $section_style; ?> <?php echo $bg_video_data_attr; ?>>
	<?php if ( ! empty( $atts['name'] ) ) : ?>
        <h1><?php echo $atts['name']; ?></h1>
	<?php endif; ?>
	<div class="<?php echo esc_attr($container_class); ?>">
		<?php echo do_shortcode( $content ); ?>
	</div>
</section>

ViorelEremia avatar May 15 '18 13:05 ViorelEremia

<h1><?php echo $atts['name']; ?></h1> contains your section name

ViorelEremia avatar May 15 '18 13:05 ViorelEremia

Hmm I've called the attached row 'test' but it is still appearing as 'section'?

screenshot 2018-05-15 17 13 21

sschristina avatar May 15 '18 16:05 sschristina