Posts: 58
Threads: 9
Joined: Jan 2012
2012-02-29, 12:32:05
(This post was last modified: 2012-02-29, 12:49:40 by VioletJim.)
I'm searching again for a php code to use in a template file.
I want to check if the content is empty (no content).
Example:
Code:
<?php if (page_content() != '') { ?>
<section class="cssborder and more">
<?php get_page_content(); ?>
</section>
<?php } ?>
Have tried "get_page_content()", "return_page_content()" and "page_content()" and "getPageContent()".
Thank you for helping again...
EDIT: I think I got it: "returnPageContent(return_page_slug())" is doing the job in v3.1. Maybe it would be helpful to add all the return outputs (if they are short/simple) for the
main Template Tags in the Wiki?
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Posts: 661
Threads: 52
Joined: Feb 2011
2012-02-29, 12:49:26
(This post was last modified: 2012-02-29, 12:56:38 by OOuineur.)
Add the below function to admin/inc/theme_functions.php or theme/yourtheme/functions.php.
It does not matter which one you add it too.
Code:
function return_page_content() {
global $content;
exec_action('content-top');
$content = strip_decode($content);
$content = exec_filter('content',$content);
return $content;
/* un-comment below if you replace the get_page_content() function in your template files */
//exec_action('content-bottom');
}
Then you can use it to return the content instead of echo it.
Or
You can do the below in your template files:
Code:
<?php
global $content;
if($content != '')
{
get_page_content();
}
?>
Posts: 58
Threads: 9
Joined: Jan 2012
Thank you mikeh! Until now I have no functions.php and prefer to continue with template.php only. But it is nice to have your code here in case I need to use functions.php.
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.
Posts: 661
Threads: 52
Joined: Feb 2011
ChriS Wrote:Thank you mikeh! Until now I have no functions.php and prefer to continue with template.php only. But it is nice to have your code here in case I need to use functions.php.
I revised my post. You do not have to use that function if you do not want to. You can stay within your template file.
Posts: 58
Threads: 9
Joined: Jan 2012
Thanks for the new piece of code. I have edited my first post at the same time as your first post here. I mean I'm using
Code:
<?php if (returnPageContent(return_page_slug()) != '') { ?>
<div class="style">
<?php get_page_content(); ?>
</div>
<?php } ?>
Does this code have some disadvantage in comparison to yours (I need to output the styling div)?
Advanced HTML5 & CSS3 coder. Simple JS & PHP hacker (not enough for new function coding). Build one webpage with GS (late 2012). Focusing on Theme customizing/Template files. Experience with WP.