Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extend if/then with private pages
#1
Hello everybody,

I would like to extend my if/then statement with an argument whether the page is set to private or not. Its content shouldn't be shown if its private.

How should I add that part to this existing code?

PHP Code:
if (!empty(returnPageContent('aktion'))) { ?>

Thank you very much in advance.
Reply
#2
Hi smsHH,

you could use nested function call to achieve this, something like:

PHP Code:
if(empty(returnPageContent('aktion''private'))) {
    if(!empty(
returnPageContent('aktion'))) {
        ...
    }


However, it is not optimal, because the file has to be read 2 times. A better option would be to write a simple custom function for this purpose:

PHP Code:
function getPublicPageContent($slug) {
    
$data getXml(GSDATAPAGESPATH.$slug.'.xml');
    if(isset(
$data) && empty($data->private)) {
        return 
exec_filter('content'stripslashes(htmlspecialchars_decode($data->contentENT_QUOTES)));
    }


You can then call this function as follows:

PHP Code:
echo getPublicPageContent('aktion'); 

;-)
Reply
#3
use getPageField for private checking, it uses pagecache in bigin s first example instead of returnPageContent
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#4
Yes, you could also use getPageField. But I think, in this case, it makes not really sense to use page cache, if only one page needs to be checked. Page cache makes sense only if $pagesArray already in memory and several pages should to be checked within a loop, for example. Or did I misunderstood something there?
Reply
#5
Thank you both, I will try that (and try to understand the code). :-)
Reply
#6
Great, it works. Thank you again!

A small question though. I need to wrap the content into some HTML. How can I achieve that the markup will be shown only if the page isn't set to private (or/and has content), too?

PHP Code:
<!-- Start Aktion -->
<
div id="aktion">
<?
php echo getPublicPageContent('aktion'); ?>
  <div class="closeaktion" title="Fenster schlie&szlig;en">&times;</div>
</div>
<!-- Ende Aktion --> 

Thank you :-)
Reply
#7
Well, you could extend your getPublicPageContent() function before it returns the page content with the markup:

PHP Code:
...
if(isset(
$data) && empty($data->private)) {
    
$content =
        
'<div id="aktion">'.
            
exec_filter('content'stripslashes(htmlspecialchars_decode($data->contentENT_QUOTES))).
            
'<div class="closeaktion" title="Fenster schließen">&times;</div>'.
        
'</div>';
    return 
$content;

Reply
#8
Simply amazing Exclamation

Thank you so much, Bigin!
Reply
#9
for future reference yeah only use page cache when you need it, if you need info on more than one page etc, but as of 3.3.x I think its always loaded, its not lazy until 3.4, where do you think the menu comes from ?
NEW: SA Admin Toolbar Plugin | View All My Plugins
- Shawn A aka Tablatronix
Reply
#10
Oh yes, that's right, the menu ... then $pagesArray has probably already been loaded
Reply




Users browsing this thread: 1 Guest(s)