I am developing a wordpress website on the thematic framework. In my child theme i have made a full width page template called resources.php
In this page template i have written custom php code which displays various custom fields related to posts of a particular category.
For Example :
<div class="download">
<ul id="portfolio" class="port">
<?php query_posts(array ( 'category_name' => 'research' , 'posts_per_page' => '-1' , 'order'=>'ASC') ); ?>
<?php while (have_posts()) : the_post(); ?>
<li class="<?php foreach((get_the_category()) as $category) { echo $category->category_nicename; echo" ";} ?> resourcelist">
<span class="doctitle"><?php the_field('document_title') ;?> <span class="date"><?php the_field('document_date'); ?></span> <span class="categry"><?php foreach((get_the_tags()) as $tag) { echo $tag->name; echo" "; } ?></span></span>
<span class="docdes"><?php the_field('document_description') ;?></span>
<span class="docpath"><a title="download" target="_blank" href="<?php the_field('document_path'); ?>">
<img border="0" src="test.png">
</a> </span>
</li>
<?php endwhile; ?>
</ul>
</div>
Now what i want to do is restrict this page to only users who have registered . I have a plugin which takes care of this for eg: page restrict
What page restrict does is it replaces whatever gets called via the page's wisiwyg editor the_content()
with the message "you need to login".
The page gets blocked however my php code does execute as its a part of the page template.
I am trying to find out a way to add all my php code to the_content();
so that the output also gets replaced with the message.
I came across this article which gave me the following code.
<?php
function demo_function( $content ) {
$someHtml = '<div class="someClass">';
$someHtml .= 'some text or code goes here';
$someHtml .= '</div>';
$filteredcontent = $someHtml . $content;
return $filteredcontent;
}
add_filter( 'the_content', 'demo_function' );
//the loop goes here
the_content();
?>
What this code does is that it adds the above HTML within the_content(); So, the next time i block the page, even the above content gets blocked. I exactly want that to happen but with my php code not this HTML.
I am really close to cracking this but because of the above syntax appends the html to the variable, I cant append so many lines of my php code via that method.
Please help me. If you have any questions feel free to ask.