How to avoid page break in dompdf - css

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.

Related

Using 'last modified' site wide, rather than on specific page/post

I want to show some text along the lines of 'This website was last updated on 10/11/2019' - I can find solutions to do this on individual pages and posts, but not something that queries the DB and finds the last update across the site.
I have tried to adapt some wp_query but failed miserably.
you can do it by Two ways:1: You can do it by using This Plugin
2: if you don't want to use this plugin you can edit function.php file add this code there
function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );
This code checks to see if a post’s published date and last modified dates are different. If they are, then it displays last modified date before the post content.
you can add css to make it look better
.last-updated {
font-size: small;
text-transform: uppercase;
background-color: #fffdd4;
}

Wordpress Plugin: How to change CSS based on user input

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();

Drupal 7 - how to add unique class name to each page?

I'm second day into Drupal and pretty confused... I need to add an unique class name to the body tag to identify each page as there are many unique styling (to repeating elements) on each page across the site.
I've found a couple of code snippets online but they haven't worked. For example I've added this into the template.php file, but it doesn't work:
function testtheme_preprocess_html(&$vars) { // my theme is called "testtheme"
$path = drupal_get_path_alias($_GET['q']);
$aliases = explode('/', $path);
foreach($aliases as $alias) {
$vars['classes_array'][] = drupal_clean_css_identifier($alias);
}
}
It's suppose to add a class to the body tag but nothing is showing up for me. Am I missing something or can someone provide another solution?
The answer of Rainfall is true but :
There are already unique class by page in drupal in body element page-NAMEPAGE
Sorry if I didn't understand you right, but you can add code to the body tag in your html.tpl.php file to make it look this way:
<body class="<?php print $classes; ?>" <?php print $attributes;?>>
And that's all. After that your body tag will automatic have css classes according to the page . Also you'll have info about node type, info about if user logged in, node id.
Let me know if it works or if I made some mistake.
Thanks and good luck!
You can modify https://www.drupal.org/project/node_class module:
1) comment function node_class_preprocess_node in node_class.module
2) insert
$node_classes = node_class($node);
if (!empty($node_classes)) $node_classes .= ' ';
$content_column_class = str_replace(' class="','', $content_column_class);
$content_column_class = ' class="'. $node_classes . $content_column_class;
in page.tpl.php
before
<section<?php print $content_column_class; ?> id="content_col">

If else not working..

I want to show a template content if ad not available
i use this code but
both ad & template content are showing
<?php
if(dt_show_ads('position=Header&before=<div>&after=</div>'))
{
?>
<!-- Some content here -->
<?php
}
else
{
include TEMPLATEPATH.'/templates/newsleft_col.tpl.php';
}
?>
dt_show_ads('position=Header&before=<div>&after=</div>') seems to not return any value. This evaluates to false in PHP.
What dt_show_ads() does, though, is to insert ad html (if there is any).
Therefor, no matter if there are ads or not, your else part is always executed.
A quick google query didn't turn up any sensible documentation on dt_show_ads for me, you might wanna try this though:
if (strlen($ads = dt_show_ads('position=Header&before=<div>&after=</div>&echo=false')) !== 0)
{
echo $ads;
// whatever other content you want to show
}
else
{
include TEMPLATEPATH.'/templates/newsleft_col.tpl.php';
}
Edit:
Since, per your comment, dt_show_ads() doesn't support the WP-semi-standard echo argument, you'll need to buffer its output to be able to check it:
ob_start();
dt_show_ads('position=Header&before=<div>&after=</div>');
$ads = ob_get_contents();
ob_end_clean();
if (strlen($ads) !== 0)
{
echo $ads;
// whatever other content you want to show
}
else
{
include TEMPLATEPATH.'/templates/newsleft_col.tpl.php';
}
There is no posibility to get both states of the IF statement. There is something wrong with your code. You may have not show up here all of your code correctly ?
Answer #2
The function that you check:
if(dt_show_ads('position=Header&before=<div>&after=</div>'))
{
}
else
{
}
It can print out the appropriate HTML and at the end return a false in example. In that case you get false for the first IF statement and the because of the false you get the else part.
To be sure what is the result of the dt_show_ads(); do that:
echo "<pre>" . print_r(dt_show_ads('position=Header&before=<div>&after=</div>'), true) . "</pre>";
<?php
if (!dt_show_ads('position=Header&before=<div>&after=</div>')) {
include TEMPLATEPATH.'/templates/newsleft_col.tpl.php';}
?>

wordpress: previous_post_link() / next_post_link() placeholder

I am having trouble with the previous_post_link() and next_post_link() functionality. When there is no previous post, the function previous_post_link() does not display a link, likewise for the next_post_link() and the last post. I would like to have a placeholder image so that the design stays consistent.
Currently I have images of green arrows pointing left and right, I would like to place an image of a grey arrow if there are no more posts to go back to.
Is there a way to use the next_post_link()/previous_post_link() functions but not have the link removed.
I also wonder if there is a way for the links to cycle, so that if you come to the most recent post, the next post link would bring you back to the first post.
************ UPDATED ************
Here is the code, based on "silent's" advice (accepted answer) to use get_adjacent_post():
<?php
if(get_adjacent_post(false, '', true)) {
previous_post_link('%link','<img src="larr.gif"/>');
}
else {
echo '<img src="larr2.gif"/>';
};
if(get_adjacent_post(false, '', false)) {
next_post_link('%link','<img src="rarr.gif"/>');
}
else {
echo '<img src="rarr2.gif">';
};
?>
So you can "capture" what next_post_link() and previous_post_link() return using ob_start() and ob_get_clean(), then apply a conditional to it.
Code in practice:
$previous_string = "<-Back";
ob_start(); // start output buffering
previous_post_link("%link", $previous_string);
$previous_link = ob_get_clean(); // stop output buffering and store
if ($previous_link == '') {
echo '<span style="color: #ccc">' . $previous_string . '</span>';
} else {
echo $previous_link;
}
I never try this myself. However, you may refer to this post. It uses get_adjacent_post().
Why cant you try the below?
<div style="float:right"><?php if(get_previous_posts_link()) { previous_posts_link('Newer Entries »'); } else { echo 'No Newer Entries'; } ; ?></div>
Alternatively to display Next and Previous Post Links to Blog post you can easily do that. This is very well explained at globinch.com (WordPress Tips : How to Add Next and Previous Post Links to Blog? )
http://www.globinch.com/2010/10/12/wordpress-tips-how-to-add-next-and-previous-post-links-to-blog/

Resources