• Hi – I have a client that is using Attachments Pro on his page to add a list of attachments to each of their projects. The attachments are loaded automatically via the page template below the post content. I tried to add the closing tag [/content_protector] to the page template below the code that loads the attachments and just the opening tag with the password on the actual page, but it doesn’t seem to work. The form for password shows even without the closing tag and then lower down on the page the closing tag is visible[/content_protector] below the attachments. Is there a way I can add the closing tag to the page template?

    https://www.ads-software.com/plugins/content-protector/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Have you looked at https://codex.www.ads-software.com/Function_Reference/do_shortcode? If you’re editing the Theme templates, something like this should work for you:

    // In case there is opening and closing shortcode.
    echo do_shortcode('[content_protector]'.$text_to_be_wrapped_in_shortcode.'[/content_protector]');
    Thread Starter tbeerejo

    (@tbeerejo)

    Hi – sorry I’m not much of a coder. Here is an excerpt from the template. I am putting the opening code with the password in the content – eg [content_protector password=”testing”] and then wanted to add the closing tag at the end of the <section class=”resources”> but the plugin is automatically closing the [content_protector password=”testing”] right before the section even though I’ve tried to add it to the below page code? I’m not sure how to use the reference that you are showing me…..

    <section>
    	<article>
    
    <?php if ( have_posts() ) while ( have_posts() ) { the_post(); 
    
    	$ap = new AttachmentsPro();
    
    	// arguments for our first instance of Attachments
    	$args   = array(
    		'post_id' 	=> $post->ID,
    	    'instance'  => 'projectfiles',
    	    'details'   => true
    	);
    
    	$files = $ap->get_attachments($args);
    ?>
    
    // In case there is opening and closing shortcode.
    
    	<h1><?php the_title(); ?></h1>
    	<dl>
    		<dt>Location:</dt><dd><?= get_post_meta($post->ID, 'project-location', true) ?></dd>
    		<dt>Status:</dt><dd><?= get_post_meta($post->ID, 'project-status', true) ?></dd>
    	</dl>
    	<?php the_content(); ?>
    
    <?php } ?> 
    
    	</article>
    </section>
    
    <section class="resources">
    
    	<h3>Project files</h3>
    
    <?php if (empty($files)) { ?>
    <p>No files found</p>
    <?php } else {
    	$byCat = array();
    
    	foreach($files as $file) {
    		$f = (object) $file;
    		$category = $f->fields[2];
    		if (empty($category)) $category = 'Uncategorized';
    
    		$byCat[$category][] = $f;
    	} 	
    
    	foreach($byCat as $c => $files) { ?>
    	<h4><?= $c ?></h4>
    	<ul>
    <?php		foreach ($files as $f) { ?>
    		<li><a class="<?= $f->mime ?>" href="<?= $f->url ?>" title="<?= $f->name ?>"><?= $f->name ?></a></li>
    <?php 		} ?>
    	</ul>
    <?php }
    }
    
    ?>
    <?php echo do_shortcode('[/content_protector]'); ?>
    
    </section>
    
    <?php get_footer(); ?>
    Thread Starter tbeerejo

    (@tbeerejo)

    Hi – sorry I’m not much of a coder. Here is an excerpt from the template. I am putting the opening code with the password in the content – eg [content_protector password=”testing”] and then wanted to add the closing tag at the end of the <section class=”resources”> but the plugin is automatically closing the [content_protector password=”testing”] right before the section even though I’ve tried to add it to the below page code? I’m not sure how to use the reference that you are showing me…..

    <section>
    	<article>
    
    <?php if ( have_posts() ) while ( have_posts() ) { the_post(); 
    
    	$ap = new AttachmentsPro();
    
    	// arguments for our first instance of Attachments
    	$args   = array(
    		'post_id' 	=> $post->ID,
    	    'instance'  => 'projectfiles',
    	    'details'   => true
    	);
    
    	$files = $ap->get_attachments($args);
    ?>
    
    	<h1><?php the_title(); ?></h1>
    	<dl>
    		<dt>Location:</dt><dd><?= get_post_meta($post->ID, 'project-location', true) ?></dd>
    		<dt>Status:</dt><dd><?= get_post_meta($post->ID, 'project-status', true) ?></dd>
    	</dl>
    	<?php the_content(); ?>
    
    <?php } ?> 
    
    	</article>
    </section>
    
    <section class="resources">
    
    	<h3>Project files</h3>
    
    <?php if (empty($files)) { ?>
    <p>No files found</p>
    <?php } else {
    	$byCat = array();
    
    	foreach($files as $file) {
    		$f = (object) $file;
    		$category = $f->fields[2];
    		if (empty($category)) $category = 'Uncategorized';
    
    		$byCat[$category][] = $f;
    	} 	
    
    	foreach($byCat as $c => $files) { ?>
    	<h4><?= $c ?></h4>
    	<ul>
    <?php		foreach ($files as $f) { ?>
    		<li><a class="<?= $f->mime ?>" href="<?= $f->url ?>" title="<?= $f->name ?>"><?= $f->name ?></a></li>
    <?php 		} ?>
    	</ul>
    <?php }
    }
    
    ?>
    <?php echo do_shortcode('[/content_protector]'); ?>
    
    </section>
    
    <?php get_footer(); ?>

    Assuming

    <ul>
    <?php		foreach ($files as $f) { ?>
    		<li><a class="<?= $f->mime ?>" href="<?= $f->url ?>" title="<?= $f->name ?>"><?= $f->name ?></a></li>
    <?php 		} ?>
    	</ul>

    is the loop that displays your attachments, try something like this instead:

    <?php
    	$protected_content = "<ul>";
    	foreach ($files as $f) {
    		$protected_content .= "<li><a class='" . $f->mime . "' href='" . $f->url . "' title='" . $f->name . '">" . $f->name . "</a></li>";
    	}
    	$protected_content .= "</ul>";
     	echo do_shortcode('[content_protector]' . $protected_content .'[/content_protector]');
    ?>

    Remove the other reference to do_shortcode() in your template.

    Thread Starter tbeerejo

    (@tbeerejo)

    Thanks – I will try it. However how will I add the password into it? By putting the shortcode with the password in the content area of the post?

    Thread Starter tbeerejo

    (@tbeerejo)

    when I replace

    <ul>
    <?php		foreach ($files as $f) { ?>
    		<li><a class="<?= $f->mime ?>" href="<?= $f->url ?>" title="<?= $f->name ?>"><?= $f->name ?></a></li>
    <?php 		} ?>
    	</ul>

    with

    <?php
    	$protected_content = "<ul>";
    	foreach ($files as $f) {
    		$protected_content .= "<li><a class='" . $f->mime . "' href='" . $f->url . "' title='" . $f->name . '">" . $f->name . "</a></li>";
    	}
    	$protected_content .= "</ul>";
     	echo do_shortcode('[content_protector]' . $protected_content .'[/content_protector]');
    ?>

    it gives me a syntax error on this line
    echo do_shortcode('[content_protector]' . $protected_content .'[/content_protector]');

    Just add the attributes into the shortcode as you’d normally do:

    <?php
    	$protected_content = "<ul>";
    	foreach ($files as $f) {
    		$protected_content .= "<li><a class='" . $f->mime . "' href='" . $f->url . "' title='" . $f->name . '">" . $f->name . "</a></li>";
    	}
    	$protected_content .= "</ul>";
     	echo do_shortcode('[content_protector password="mypassword"]' . $protected_content .'[/content_protector]');
    ?>

    Check your opening and closing PHP tags; you likely have a mismatch.

    Thread Starter tbeerejo

    (@tbeerejo)

    That is part of my problem. My client wants the password to be unique on each page, so I don’t want to to add it into the page code. Thanks for your help I’m not sure this is going to work. Ill see if the client is ok with just one password I guess.

    Can’t you use the Attachments Pro plugin on individual Posts/Pages?

    Thread Starter tbeerejo

    (@tbeerejo)

    Unfortunately this is not my site, its one I’d been asked to work on. The site is custom, and the project posts are using a custom page template that loads the attachments from Attachments pro. (per the code above) below the content. I can use your plugin fine on the page template if I put it in the content, but the problem is the attachments are loading below the <?php the_content(); ?> Basically the shortcode has to go around this entire block of code

    <section class="resources">
    
    	<h3>Project files</h3>
    
    <?php if (empty($files)) { ?>
    <p>No files found</p>
    <?php } else {
    	$byCat = array();
    
    	foreach($files as $file) {
    		$f = (object) $file;
    		$category = $f->fields[2];
    		if (empty($category)) $category = 'Uncategorized';
    
    		$byCat[$category][] = $f;
    	} 	
    
    	foreach($byCat as $c => $files) { ?>
    	<h4><?= $c ?></h4>
    	<ul>
    <?php		foreach ($files as $f) { ?>
    		<li><a class="<?= $f->mime ?>" href="<?= $f->url ?>" title="<?= $f->name ?>"><?= $f->name ?></a></li>
    <?php 		} ?>
    	</ul>
    <?php }
    }
    
    ?>
    <?php } ?>
    </section>

    I really appreciate you taking the time to respond to me. I hope this explains it better. Thank you so much.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Add the closing tag[/content_protector] to the page template’ is closed to new replies.