I'm trying to make a php site read from a text file by using this:
<html>
<head>
<title>This is a test!</title>
</head>
<body>
<?php
$f = fopen("testfile.txt", "r");
// Read line by line until end of file
while(!feof($f)) {
echo fgets($f) . "<br />";
}
fclose($f);
?>
</body>
</html>
-and it works!
Next step is to make the php site read text with links inside.
This is the text in the text file within a link, please press this link www.stackoverflow.com and more text to come after the link. Linktext like "THIS IS A LINK" is also needed.
Hope you understand what I want:)
How do I do something like this?
From reading your: "I want seperate text files for the different text sections on the site."
Have you considered using a separate php file "setting.php" and inside making a multidimensional array with all the things you need?
<?php
$settings = array(
'header_text' => array(
'text' => 'This is my header text and it containts a link click here',
'color' => '#000000',
'font-size' => '12px'
),
'footer_text' => array(
'text' => 'Copyright © Terms and Conditions',
'color' => '#000000',
'font-size' => '12px'
),
);
?>
and if you need to go a step deeper and do it PER page:
<?php
$settings = array(
'index.php' => array(
'header_text' => array(
'text' => 'This is my header text and it containts a link click here',
'color' => '#000000',
'font-size' => '12px'
),
'footer_text' => array(
'text' => 'Copyright © Terms and Conditions',
'color' => '#000000',
'font-size' => '12px'
)
),
'about.php' => array(
'header_text' => array(
'text' => 'This is my header text and it\'s only for the about page and it containts a link click here',
'color' => '#000000',
'font-size' => '12px'
),
'footer_text' => array(
'text' => 'Copyright © Terms and Conditions and go to the main index page',
'color' => '#000000',
'font-size' => '12px'
)
),
);
?>
you can then include this file in your main script
include('settings.php');
and then call upon the array and such, all you do it edit the php file, and any changes would update.
This way you can manually edit any details you want!
Example:
<?php include('settings.php'); $curr_page = basename($_SERVER['PHP_SELF']); ?>
<div style="color: <?php echo $settings['header_text']['color']?>"><?php echo $settings[$curr_page]['header_text']['text']?></div>
<div style="color: <?php echo $settings[$curr_page]['header_text']['color']?>"><?php echo $settings[$curr_page]['header_text']['text']?></div>
Thanks for your great answer - it was easy to understand.
I need to make my php site read from a text file because it is my boss who needs to change text on the site, and I don't want him to delete any of the coding.
So, is there any way to make the php site read from a text file?
This is a text 1 (must be read from document 1)
This is another text (must be read from document 2)
This is another text section on the php and THESE WORDS shuld be a hyperlink in the middle of the sentence.
etc...
Thanks again!
Related
I'm trying to add a new field to Admin Preferences - a textarea field with tinymce. I've added code to AdminPreferencesController.php:
$this->fields_options['contact'] = array(
'title' => $this->l('Contact'),
'icon' => 'icon-cogs',
'submit' => array('title' => $this->l('Save')),
);
$this->fields_options['contact']['fields']['PS_CONTACT_ADDITIONAL_INFO'] = array(
'type' => 'textarea',
'label' => $this->l('Short description'),
'name' => 'short_description',
'lang' => true,
'cols' => 60,
'rows' => 10,
'autoload_rte' => 'rte',
'col' => 6,
);
But tinymce doesnt' appear and when I'm using HTML tags after saving they disappear. Presta strips all HTML tags.
How to allow HTML tags on this field and enable tinymce?
It seems that you can't just add it in a regular way. But you can implement it in a next way.
First of all, use field type textareaLang instead of textarea and add a parameter 'validation' => 'isCleanHtml' to this field
$this->fields_options['contact']['fields']['PS_CONTACT_ADDITIONAL_INFO'] = array(
'type' => 'textareaLang',
'label' => $this->l('Short description'),
'name' => 'short_description',
'lang' => true,
'cols' => 60,
'rows' => 10,
'col' => 6,
'validation' => 'isCleanHtml'
);
Create your own script to initialize your editor. I created a script tinymce.init.js and put it to js/admin/ folder
$(document).ready(function(){
ad = ''; // this is defenition of the external plugin path. I didn't fint how it can impact on script if it's empty but by default it it the path to your admin folder
iso = iso_user;
var config = {
selector: '.textarea-autosize'
};
tinySetup(config);
});
Then include tinymce script and your own to this controller AdminPreferencesController.php
public function setMedia()
{
$this->context->controller->addJquery();
$this->context->controller->addJS(
array(
_PS_JS_DIR_.'admin/tinymce.init.js',
_PS_JS_DIR_.'tiny_mce/tiny_mce.js',
_PS_JS_DIR_.'admin/tinymce.inc.js'
)
);
parent::setMedia();
}
It should implement your requirements. But don't forget that now you should call your configuration field in multilingual scope. So, add a language id to Configuration::get() like
Configuration::get('PS_CONTACT_ADDITIONAL_INFO, $id_lang)
whenever you use it.
P.S. Bear in mind that the best solution for your goal is to create a simple module which will handle this. And far more, it is recommended way.
<div class='rate-results'>
<div class='button-container'>
<input type='submit' id='btn-calculate' class='pure-button pure-button-primary' value='{$a['label_button_continue']}'></input>
</div><div class='rate-container'>
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
<div id='calculated_rate'>{$a['default_price']}</div>
</div>
how can i apply a link to this button?
['label_calculated_rate']
seems to pull the text
"GET A QUOTE"
from code up above it, but nowhere can i find how to turn this button into a link. The mentioned above code is as follows...
static function handle_shortcode($atts){
self::$add_script = true;
self::$add_styles = true;
$a = shortcode_atts( array(
'title' => 'Get a FREE Price Estimate',
'label_days' => 'Total days of coverage needed?',
'units_days' => 'days',
'label_attendance' => 'Estimated daily attendance?',
'units_attendance' => 'people',
'label_event_type' => 'What type of event is it?',
'label_sample_certificate' => 'View sample certificate',
'link_sample_certificate' => '#',
'label_button_continue' => 'Get Free Quote',
'label_calculated_rate' => 'Estimated Cost',
'default_price' => '$ 95.95',
'form_action' => 'javascript:void(0);',
'default_event_type' => ""
), $atts);
return "<form action='{$a['form_action']}' id='main_calculator' class='pure-form pure-form-aligned' data-default-event-type='{$a['default_event_type']}'>
<h3 class='title'>{$a['title']}</h3>
Replace
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
with
<div class='label_calculated_rate'>{$a['label_calculated_rate']}</div>
Replace http://www.w3schools.com/html/ with where you want the button to link to.
Hence adding a link to the button:
['label_calculated_rate']
I'm a beginner in writing PHP, but working on developing themes in WordPress.
I have no idea how to echo my style option within my front-page.php.
My meta.php:
$meta_style = array();
$meta_style['meta_style'] = array(
'dash_icon' => 'list-view',
'title' => __('Section Settings', 'fluent'),
'description' => __('These are general section settings.','fluent'),
'context' => 'normal',
'priority' => 'high',
'option_name' => 'meta_style',
'caps' => array(),
'fields' => array(
'style' => array(
//...
'type' => 'select',
'options' => array(//option value = option label
'value' => 'white',
'value2' => 'black'
),
'multiple' => false,//allow multiple values to be selected - default false
'placeholder' => 'white'//placeholder text for the element
),
),
);
My front-page.php (it's wrapped in a BUTTON just a see if the variable echoes):
<button>
<? if($meta = get_post_meta($post->ID)){ if($meta['style'] == true){ echo $meta['value']; } } ?>
</button>
Can anyone provide an additional examples on how to echo other types, such as 'type' => 'text'?
I dont know exactly what you want, but you should:
1 - See if you're echoing the right information
2 - Use var_dump()
In your first code example you have a variable $meta_style which is a map. It has one key, 'meta_style' that leads to a next map. Inside that inner map you have the keys 'dash_icon' and so on. So for example this should echo the string 'normal':
echo $meta_style['meta_style']['context'];
However, in your second example, you have a variable $meta which is also a map, having keys 'style' and 'value'. You could echo those with:
echo $meta['style'];
echo $meta['value'];
Based on your example, I have no idea what these should do or how they should be related, or what their meaning should be.
I am helping a buddy out and modifying his Wordpress portfolio for him. I don't use php very often so this might be something simple.
In a template I am calling the Wordpress the_field() method like so:
<?php echo the_field('full_text'); ?>
This is outputting the content of the full_text just fine however the full_text does contain an <a> tag which is not being generated as a link and is showing up as:
The Link
instead of actually generating the link.
What do I need to do to get any HTML contained in the full_text field to show up as HTML and not plain text?
Edit
In custom_fields.php I've found:
array (
'key' => 'field_4',
'label' => 'Full Text',
'name' => 'full_text',
'type' => 'textarea',
'order_no' => 2,
'instructions' => 'Write about this item.',
'required' => 0,
'conditional_logic' =>
array (
'status' => 0,
'rules' =>
array (
0 =>
array (
'field' => 'null',
'operator' => '==',
'value' => '',
),
),
'allorany' => 'all',
),
'default_value' => '',
'formatting' => 'br',
),
It seems like you're using Advanced Custom Fields. If so, you need to turn off the "filter content" setting to get the link to show up.
Thanks to mcrtr I was informed that the template he was using was using Advanced Custom Fields digging deeper I found the field full_text was of type textarea by changing it to wysiwyg it no longer outputted as plain text.
When setting up the field, change the formatting option to HTML instead of none and it'll keep the <a> tag around your link.
You don't need to change it to WYSIWYG in order to keep links as links in ACF.
Folks,
I'm currently setting up a WP install. In order for the client to access a custom help-document, I added an additional dropdown menu in the admin-bar as a WP plugin via the following php-file:
<?php
function pub_admin_bar_init() {
if (!is_super_admin() || !is_admin_bar_showing() )
return;
add_action('admin_bar_menu', 'pub_admin_bar_links', 500);
}
add_action('admin_bar_init', 'pub_admin_bar_init');
function pub_admin_bar_links() {
global $wp_admin_bar;
$links = array(
'Chapter 1' => 'http://manual.domain.com/index1.html',
'Chapter 2' => 'http://manual.domain.com/index2.html',
'Chapter 3' => 'http://manual.domain.com/index3.html',
'Chapter 4' => 'http://manual.domain.com/index4.html',
'Chapter ...' => 'http://manual.domain.com/index5.html',
);
$wp_admin_bar->add_menu( array(
'title' => 'Help-Document',
'href' => false,
'id' => 'pub_links',
'href' => false
));
foreach ($links as $label => $url) {
$wp_admin_bar->add_menu( array(
'title' => $label,
'href' => $url,
'parent' => 'pub_links',
'meta' => array('target' => '_blank')
));
}
}
?>
The dropdown works fine and the referenced html-files located in the subdomain of the same domain get called in a new tab.
However, in order to have everything neatly arranged within the WP admin, I'd like to call the menu items in the new admin-bar dropdown via an iframe Lightbox.
I managed to set this up in the Dashboard intro section using the built-in thickbox with the following syntax:
<a style="text-decoration:none;"
href="http://codex.wordpress.org/First_Steps_With_WordPress?
keepThis=true&TB_iframe=true&height=800&width=1200" class="thickbox"
title="sometitle">First Steps with WordPress</a>
This lets me call the html help-files (or any other url for that matter) as an iframe in a thickbox-style overlay.
Now my actual question:
Could someone point me to how I could make the links in the admin-bar dropdown ('Chapter 1' => 'http://manual.domain.com/index1.html', ...) as thickbox-style overlays instead of target=_blank?
Help very much appreciated. Thanks a lot!
'meta' => array('target' => '_blank'),
You forget of ","