I've created a plugin for Wordpress that display's a bunch of information in a table.
I have an options page where you can enter a color for odd, and even rows. The options page saves the user input fine. But I'm not sure how to update the CSS with the user input.
This is what I have, it technically works, but when I place any other widget in my sidebar, all the options of that widget disappears. So I'm obviously doing something wrong. There must be a better way.
ob_start();
function change_row_color(){
global $odd;
global $even;
if(!get_option('gfd_rc_odd')){
$odd = "eee";
}else{
$odd = esc_attr(get_option('gfd_rc_odd'));
}
if(!get_option('gfd_rc_even')){
$even = "fff";
}else{
$even = esc_attr(get_option('gfd_rc_even'));
}
?>
<style type="text/css">
#stockchart tr:nth-child(odd){
background-color:#<?php echo $odd; ?>;
}
#stockchart tr:nth-child(even){
background-color:#<?php echo $even; ?>;
}
</style>
<?php
}
change_row_color();
Related
I am displaying some question answers in my pdf. But in some cases, the question s on one page and answer will come to the next page. I want to avoid that situation. I want to display question and answer in same page either in first page or next page. I have tried the CSS as below:
.questiontext
{
unbreakable: true
}
But it is not working for me. Please help me.i added pdf helper and view page as below.
$d_arr=date('Y-m-d H:i:s');
$location_name="test"
$list_content=$this->generate_form_list($submission_id,$client_id);
$filename_proposalpdf="formname.pdf";
$this->load->helper(array('dompdf', 'file'));
pdf_create_proposal($list_content,$filename_proposalpdf,true);
in generate formlist i added view page as below:
public function generate_form_list($id,$client_id)
{
$data['form_data']=$this->Mobile_app_model->get_form_list($id,$client_id);
$data['client_data']=$this->Mobile_app_model->get_client_data($client_id);
$data['client_idsss']=$client_id;
return $this->load->view('pdf_formlist',$data,true);
}
In view page just i have displayed the data as below:
<?php
foreach($task_data as $fdata)
{
echo '<p class="questiontext">';echo $fdata['question_text'];echo '</p>';
echo '<p id="lableanswer">';echo $fdata['answer'];echo '</p>';echo '<br/>';
}
?>
Please help me how to make both are in one page.
The unbreakable property is used to prevent line breaks, not page breaks.
What you're looking for is:
.question
{
page-break-inside: avoid;
}
You can find more detailed reference in this External reference
Addressing your comment below, the problem is that you need to wrap both the question and the answer within a single element styled with page-break-inside: avoid;
.dontsplit
{
page-break-inside: avoid;
}
<?php
foreach($task_data as $fdata)
{
echo '<div class="dontsplit">';
echo '<p class="questiontext">';echo $fdata['question_text'];echo '</p>';
echo '<p id="lableanswer">';echo $fdata['answer'];echo '</p>';echo '<br/>';
echo '</div>';
}
?>
If you style the dontsplit class with page-break-inside: avoid; you'll get the whole question-answer block to remain together avoiding page breaks.
I have a site powered by wordpress. I need to hide the navigation menu in two specific pages but I couldn´t do it.
This is the page:
The menu is appearing like this:
In the bottom left side of the page. It´s need to be hide or remove.
Above, is the html of the menu
I tried this use this code:
.mob-menu-header-holder .mobmenu .mobmenur-container .mob-menu-left-panel .mobmenu_content .leftmtop .mob-menu-right-panel{display: none;}
Any ideas?
please try add this code in your functions.php
add_action('wp_head', 'add_css_head');
function add_css_head() {
if ( is_page( 'your-page-slug' ) || is_page( 'your-page-slug' ) ) {
?>
<style>
.your-css-class {
display:none
}
</style>
<?php
}
}
if one of page you want to hide is frontpage you can use this
add_action('wp_head', 'add_css_head');
function add_css_head() {
if ( is_front_page() || is_page( 'your-page-slug' ) ) {
?>
<style>
.your-css-class {
display:none
}
</style>
<?php
}
}
First of all you have to access your wordpress files. Then find custom .css or .less file if it's exist. And then add this code line in this file. But this line affect to whole site pages. So, if you want to affect only two pages, you have to add some codes to in your theme's index.php (I guess) file.
.mobmenu{ display:none!important; }
I'm currently building links like this:
<?php echo get_the_title(111); ?>
I was building links like this using the WPML plugin (but steering away from it due to various reasons):
<?php icl_link_to_element(111); ?>
This builds a link similar to my first example.
So my question is is there a native Wordpress function that does this? I'm sure there must be, but cannot find the solution anywhere. I'm looking to reduce my markup...
Thanks!
EDITED WITH ANSWER
This is how I built my custom function:
function build_pretty_link($id,$link_title='') {
if($link_title=='') {
$link_title = get_the_title($id);
}
$link_url = get_permalink($id);
echo "{$link_title}";
}
WordPress give a function that print an anchor tag with the title and the url, but you have to be in a the loop (http://codex.wordpress.org/Function_Reference/permalink_anchor).
I suggest you to create your own function (the functions.php file in your theme is here for that).
You can do someting like that :
function vp_link_to($post_id) {
echo '<?php echo get_the_title($post_id); ?>';
}
get_permalink(x);
Where the ID of the page is x and wrap this in whatever you need, so
$id = 10;
$link = get_permalink($id);
echo 'Linked text';
PHP getimagesize is not working when is called from a function in function.php.
function.php:
<?php
// Theme Options
require_once(TEMPLATEPATH . '/functions/admin-menu.php');
add_action('wp_head', 'theme_options', 'get_image_size');
function theme_options() {
// Initiate Theme Options
$options = get_option('plugin_options');
// If a logo image was uploaded then remove text from site title
if ($options['logo'] != NULL)
$remove_text = '-9999px';
else
$remove_text = 0;
?><style>
body {
background-color: <?php echo $options['color_scheme']; ?>
}
#header h1 a {
background: url(<?php echo $options['logo']; ?>) no-repeat scroll 0 0;
text-indent: <?php echo $remove_text; ?>;
}
</style><?php
}
function get_image_size() {
list($width, $height, $type, $attr) = getimagesize($options['logo']);
echo "Image width " .$width;
echo "<BR>";
echo "Image height " .$height;
echo "<BR>";
var_dump($width);
var_dump($heigt);
}
$options['logo'] is returning http://localhost/wordpress/wp-content/uploads/2010/12/logo4.png so the image is being displayed.
I also did var_dump to $width and $height but they didn't show up.
Any suggestions?
EDIT: I pasted the full code of functions.php. $options['logo'] works perfectly in the theme_option function so I don't know why it doesn't work in the get_image_size function.
$options['logo'] is undefined in your code. If it is defined outside of your function, it is not by default available inside of your function.
Please enable error reporting using ini_set('display_errors', 1) and error_reporting(E_ALL), when developing. This will make sure any errors are reported.
I you do not see any error messages, turn up error_reporting and display_errors.
$options['logo'] works perfectly in
the theme_option function so I don't
know why it doesn't work in the
get_image_size function.
As #Sjoerd said: $options is not defined in function get_image_size. It is only defined in function theme_options. That's what functions are about, they are a black box that know about their environment only from the arguments they receive. If you want to make the options visible in function get_image_size, you have to Initiate Theme Options in that function as well.
I found out how to fix it (separating the functions into different add_action statements):
add_action('wp_head', 'theme_options');
function theme_options {
...
}
add_action('wp_head', 'get_image_size');
function get_image_size {
...
}
The add_action only allows one function?
What was the problem?
Is there a plugin or something that creates PDF files from a entered by the user form data, when it clicks on the submit button?
if youre wanting a form filled in, then the details of that form processed and sent to you via email with a pdf attachment of the details, i had something similar a few weeks back, I couldnt find anything that would work the way i wanted, so....
I setup my form then using a custom page template I assigned that to a page, then using php and the html2pdf class i created my pdf which was emailed as an attachment...
heres the code i used..
been minified for this page (remember to sanitize your user input).
<?php
/*
Template Name: FORMTOPDF
*/
?>
<?php get_header(); ?>
<style>
/* STYLES FOR ERROR PLACEMENT */
label {
width: 80px;
text-align: right;
float: left;
}
.formerror {
border: 1px solid red;
background-color : #FFCCCC;
width: auto;
padding: 5px 0;
padding-left:10px;
}
.errortext {
font: bold smaller sans-serif;
}
</style>
<?php
// CREATE AN ARRAY FOR OUR ERRORS
$arrErrors = array();
// Check for FORM SUBMISSION
// using hidden form field
if(isset($_POST['action']) && ($_POST['action']=='send'))
{
/* ================= START FORM DATA ========================= */
$name = trim($_POST['name']);
if ($name=='') $arrErrors['name'] = 'Please provide your name.';
$email = trim($_POST['email']);
if ($email=='') $arrErrors['Email'] = 'Please provide your Email Address.';
$comments = trim($_POST['your-comments']);
if ($comments=='') $arrErrors['Comments'] = 'Please add your Comments.';
/* ================= END FORM DATA ========================= */
if (count($arrErrors) == 0) {
// Process form here
/* ================= START PDF CREATION ========================= */
$strContent = "<p>Submission from ".$name."</p>";
$strContent.= "<p><strong>Name</strong>:".$name."</p>";
$strContent.= "<p><strong>Email </strong>: ".$email."</p>";
$strContent.= "<p><strong>Comments</strong> : <br />".$comments."</p>";
/* ================= END PDF CREATION ========================= */
// Include our HTML to PDF creator
// FROM THEME DIRECTORY?
require(TEMPLATEPATH.'/html2pdf/html2fpdf.php');
$pdf=new HTML2FPDF();
$pdf->AddPage();
// folder location of HTML file
$fileLocation = "wp-content/uploads/";
// Call to the file name from the URL
$fileName = "Form_Submission_From_".$name;
// add the location 'wp-content/uploads/' to the fileToOpen
$fileToOpen = $fileLocation;
// Then add the actual file name // form_submission.pdf
// output should look like 'wp-content/uploads/form_submission_from_(name).pdf'
$fileToOpen .= $fileName.".pdf";
// Open the file with read access
$fp = fopen($fileToOpen,"r");
//$strContent = fread($fp, filesize($fileToOpen));
// Close of the page
fclose($fp);
// Create new PDF document from the Content
$pdf->WriteHTML($strContent);
// create our PDF in the wp uploads folder
$pdf->Output("wp-content/uploads/" .$fileName. ".pdf");
/* ================= END PDF ========================= */
/* ================= START EMAIL ========================= */
$headers= "From: YourWebsite <info#yourwebsite.co.uk>\r\n\\";
$emailSubject = "Submission from " . $name;
$emailAdmin = "admin#yourwebsite.co.uk";
$emailMessage = "Submission from ".$yourcompanyname."\n\n";
$emailMessage.= "Company Name: ".$yourcompanyname."\n";
$emailMessage.= "Email : ".$email."\n";
$emailMessage.= "Comments : \n".$comments."\n\n";
$attachments = array(WP_CONTENT_DIR ."/uploads/".$fileName.".pdf", $target_path);
wp_mail($emailAdmin, $emailSubject, $emailMessage, $headers, $attachments);
// Delete our PDF from the server after email Sent
// uncomment this to delete after email sent?
//unlink($fileToOpen);
/* ================= END EMAIL ========================= */
// show thank you message if successful
$strGood = '<div class="formerror" style="background:#FFC;">
<h2>Thank You</h2>
<p>Thank you for contacting us.</p>
</div>';
}else{
// The error array had something in it. There was an error.
// Start adding error text to an error string.
$strError = '<div class="formerror"><p><img style="margin-left:10px;" src="'.get_option('home').'/wp-content/themes/mytheme/media/images/triangle_error.gif" width="16" height="16" hspace="5" alt=""><strong>Please check the following and try again:</strong></p><ul style="margin-left:50px;">';
// Get each error and add it to the error string
// as a list item.
foreach ($arrErrors as $error) {
$strError .= "<li style='list-style-type:circle;'><em>$error</em></li>";
}
$strError .= '</ul></div><br />';
}
}// NOT BEEN SUBMITTED
// show regular page with form
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="post" id="post-<?php the_ID(); ?>">
<h2>
<?php the_title(); ?>
</h2>
<?php
// show errors if there is any
echo $strError;
?>
<?php
// show thank you if successful
echo $strGood;
?>
<?php the_content('<p>Read the rest of this page »</p>'); ?>
<form method="post" action="<?php bloginfo('url');?>/your-form-page/" enctype="multipart/form-data">
<input type="hidden" value="send" name="action">
<p <?php if (!empty($arrErrors['name'])) echo ' class="formerror"'; ?>>Your Name:
<span class="errortext" style="color:#F00;">(required)</span><br>
The rest of the form below here ------ >
</form>
<?php endwhile; endif; ?>
<?php get_footer(); ?>
thats it, once the user fills out the form, (my form had a lot more fields than this plus an upload field for files to be attached also.)
but the forms submitted, checks for required fields, if successful it will create a pdf file from the $strContent variable, then attaches this to the email to be sent using the wp_mail from wordpress.. then displays a thank you message, or else it will show and highlight any errors,
hope this helps..
I found these plugins that allow posts to be emailed or downloaded as pdf's.
http://wordpress.org/extend/plugins/tags/create-pdf
If you are flexible, It seems possible to programmatically create posts from your form submitted by a user, then create a pdf of that post. The posts that are created from the form could easily be assigned a particular category which is not displayed on the site.
To programmatically create, update, and delete posts, see the WordPress Function Reference, and in particular:
wp_insert_post
wp update post
wp delete post
A quick google search exhibits plenty of ways to create pdf's with php. Some hard, some less hard. I found this class that might get you started: "FPDF"
There is a plugin extension called Gravity PDF, that extends from Gravity Forms. It will generate a PDF from a form, and you can choose to download or email it.
Source
https://wordpress.org/plugins/gravity-forms-pdf-extended/
I haven't done an exhaustive search of the WP-plugins, but from as far as I can tell the answer is no. Of course, it would be possible to create such a plugin from scratch however the server hosting WP would need to have the proper libraries installed in order for the plugin to be useful.
We created a custom solution for one of our clients to get this done since there weren't any ready available plugins. This system creates pdf/word documents by fetching data from Gravity Forms.
You can check out details of the solution here. Gravity Forms to PDF/Word Document Auto-Fill Soluion