I write a custom type for wordpress which is contain a textarea. I can save it and also i can access from single view. But i want to show them line by line if author save it line by line. But it's not showing them line by line, it shows all of them as a single line.
Here is my single.php's custom meta show codes;
<div id="yemek_resim">
<?php if($tz_image_display == 'true') : ?>
<?php if ( (function_exists('has_post_thumbnail')) && (has_post_thumbnail()) ) : /* if post has post thumbnail */ ?>
<?php the_post_thumbnail('single-large'); ?>
<?php endif; ?>
<?php endif; ?>
</div><!-- yemek_resim -->
<div id="yemek_malzemeleri">
<?php
$malzemeler = get_post_meta($post->ID, 'ofa_yemek_malzemeler', true);
echo esc_attr($malzemeler);
?>
</div><!-- yemek_malzemeleri -->
here yemek_malzemeler's content come from a textarea and author can write multiline content. But at site, they seem as a single line...
You should use the N2BR PHP function in the output file. Just write <?php echo n2br($string); ?> in the single.php file from Wordpress. Good luck ;)
I resolved the problem by using <pre> </pre> tags. thanks for your care.
Related
I'm trying to output content from an Advanced Custom Fields (ACF) in my wordpress theme. At the moment though, all I'm getting is the plain text content from the ACF inside double quotation marks, not inside the div and h1 tags.
The code is copied from another theme I made where it worked, which makes me think something is interfering with it somewhere?
<?php $process_title = the_sub_field('process_title'); ?>
<?php if(!empty($process_title)) : ?>
<div class="process-title">
<h1 class="process-heading">
<?php echo $process_title; ?>
</h1>
</div>
<?php endif; ?>
Thanks to #M.Eriksson, the correct code should be:
<?php $process_title = get_sub_field('process_title'); ?>
<?php if(!empty($process_title)) : ?>
<div class="process-title">
<h1 class="process-heading">
<?php echo $process_title; ?>
</h1>
</div>
<?php endif; ?>
I was referring the page.tpl.php(Drupal 7 theme) for understanding the code. I found the following code,
<?php if ($site_name || $site_slogan): ?>
<!-- !Site name and Slogan -->
<div<?php print $hgroup_attributes; ?>>
<?php if ($site_name): ?>
<h1<?php print $site_name_attributes; ?>><?php print $site_name; ?></h1>
<?php endif; ?>
<?php if ($site_slogan): ?>
<h2<?php print $site_slogan_attributes; ?>><?php print $site_slogan; ?></h2>
<?php endif; ?>
</div>
<?php endif; ?>
Can you see the code in third line, <div<?php print $hgroup_attributes; ?>> WHY the php code is inside the first div tag of html? Same thing in later part of code also, as you can see h1 and h2 code. So, what is this convention of combining the html and php in so complicated way? and how should I read that?
Combining HTML and PHP code in Drupal templates is actually a very strong feature. In this case, $hgroup_attributes will probably contain some classes that style the div. Printing it in the template results in something like
<div class="SOME_CLASSES"> ... </div>
If you're further interested in the variable $hgroup_attributes, you can inspect by pasting <?php dpm($hgroup_attributes); ?> in your template file after you've installed the Devel module.
Hy all! From what I read, the best way to add PHP code to a wordpress page would be via a custom template. So i took the page.php from the theme and customised it with html code without any problems. The problem is with the PHP code. No matter where I add it, it doesn't work.
My question is where do I add the custom PHP code for the form validation?
The page looks like this:
/*
Template Name: example
*/
<?php
get_header();
if ($tempera_frontpage=="Enable" && is_front_page()): get_template_part( 'frontpage' );
else :
?>
<section id="container" class="<?php echo tempera_get_layout_class(); ?>">
<div id="content" role="main">
<?php cryout_before_content_hook(); ?>
<?php get_template_part( 'content/content', 'page'); ?>
I added the HTML code here:
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?> " >
.....
</form>
<?php
endif;
get_footer();
?>
According to this, you will add it before the HTML, near the top of your code.
Well basically it's PHP and should work, if you want to validate the form in the same template file, use an empty action attribute:
<form method="post" action="">
.....
</form>
And make sure not to use an WordPress reserved word on your form element name attribute, for example name.
At the top of the file you can verify and validate all the request being sent by the form as any other PHP file.
<?php
if (!empty($_POST)) {
//validate or do something here
}
get_header();
if ($tempera_frontpage=="Enable" && is_front_page()): get_template_part( 'frontpage' );
else :
?>
Hope this solution help you out.
I'm thinking you should be modifying the content-page.php template. Note the page template calls it with:
<?php get_template_part( 'content/content', 'page'); ?>
Within the content template you should see something like
<?php the_content(); ?>
If you add the form html on the next line, it will be within the same div, something like
<div class="entry-content>
</div>
This way the new content will fall within the same container as other content and be styled as such.
I am using this PHP Code on my website to get wordpress page content from the database:
$page = get_page_by_id($records["value"], OBJECT, 'page');
query_posts('p='.$page->ID.'');
echo '<div id="page-title">'.$page->post_title.'</div>';
echo nl2br($page->post_content);
echo '<p> </p><hr /><p> </p>';
in wordpress, i have put the page with HTML and aligned images etc but when it displays on my website it just shows the images and text all under each other with the incorrect format (not as i put it in the text editor)
what have i done wrong here?
Im also wondering why you are doing like this? there is no need to call post title and content that way. simply make a page.php. The TwentyFourteen does have page template but in a folder named "page-templates". You can simply make a page.php by sample code below.
<?php get_header(); ?> //the header template
<?php while ( have_posts() ) : the_post(); ?> //start the loop
<?php the_title(); ?> //Page Title
<?php the_content(); ?> //The content
<?php endwhile; ?> //end loop
<?php get_sidebar(); ?> //sidebar template
<?php get_footer(); ?> // footer template
you can add div / span wherever you want.
I'm very newbie regarding PHP, I'm trying to configure my wordpress Loop.
I figured out how to display my customfield in my template, I manually added a title before my taxonomy and custom fields, but I'd like it doesn't show if the taxonomy is empty.
Here is the code:
<div class="customfields">
<h2 class="widgettitle">My Title</h2>
<?php echo do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
I would very much appreciate your help!
Thanks a ton,
T.
So code should be
<?php $taxonomy = do_shortcode('[tax id="agences" before="Agences : " separator=", " after=""]'); ?>
<div class="customfields">
<?php if(!empty($taxonomy)) : ?>
<h2 class="widgettitle">My Title</h2>
<?php echo $taxonomy; ?>
<?php endif; ?>
<?php echo do_shortcode('[custom_fields_block]'); ?>
</div>
If you want to show content in HTML only if certain variables contain a value then you can create a simple if statement that uses PHP's isset function to determine whether or not the variables are set, and if true place some HTML on the page. You can read more about isset here.