• 0

Add php to every page / every template


Question

Posted · Report post

Hi

 

I need to add some code to each and every page / template. In this instance a new 'section' for the code simply won't cut it as the code is writing it's own div/content and so the section is erroneous. 

 

As a standard 'theme' this would be easy, but how can i achieve this with DMS?

 

Thanks

 

Glennyboy

Share this post


Link to post
Share on other sites

6 answers to this question

  • 0

Posted · Report post

Use an 'action' to insert your PHP into every page.

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

like?

Well, as you didn't include any info as to where you want the code, i'll proceed to make one up...

 

I want to add a div before the postloop on every page... http://screencast.com/t/8Id7FTmYZdUm Using actionmap i find the action i want...

 

add_action( 'pagelines_before_postloop', 'add_my_loop_div' );

function add_my_loop_div() {

    echo '<div id="glenny">Hello World!</div>';

}

 

what if i only want it on post ID 234?

 

add_action( 'pagelines_before_postloop', 'add_my_loop_div_234' );
function add_my_loop_div_234() {
    if( ! is_page( 234 ) )
        return false;
 
    echo '<div id="glenny">Hello World!</div>';
}

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

ok apologies I should have been more specific. Here is the php I actually want to output:-

 

<?php if( $images ): ?>
        <ul class="cb-slideshow">
            <?php foreach( $images as $image ): ?>
<li style="background-image:url('<?php echo $image['url']; ?>');"></li>


            <?php endforeach; ?>
        </ul>


<?php endif; ?>

I presume there is no way to write directly to a single.php or equivalent file?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

no, you need to use an action or filter.

 

What is $imges? Where is that variable being set?

Share this post


Link to post
Share on other sites
  • 0

Posted · Report post

That is a very good question :D  as its something I've had issues with. $imges is set by the act plugin under:-

 

http://www.advancedcustomfields.com/resources/field-types/gallery/

 

... about half way down the page.

 

Hopefully you are going to tell me how to gather the field or ignore it if it isn't present... as my tests aren't outputting it even though the field is being served on the page

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now