Jump to content

Archived

This topic is now archived and is closed to further replies.

glennyboy

Add php to every page / every template

Recommended Posts

glennyboy    9
glennyboy

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
Simon    247
Simon

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

Share this post


Link to post
Share on other sites
Simon    247
Simon

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
glennyboy    9
glennyboy

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
Simon    247
Simon

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
glennyboy    9
glennyboy

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

  • Similar Content

    • Jared Smith
      By Jared Smith+
      I haven't figured out how to get the "Sync Loaded Item" option in templates menu of Platform 5 to stay checked. It doesn't give me an option to save settings when I select it, and when I select it then click off the editor, it unselects. Also if I select it before loading a template, it doesn't stay checked there either.  Whats going on?
    • Queue-it
      By Queue-it+
      Hi,
      I created a Pagelines template for a "Post type" post. Whenever creating a new post page it firstly display that template post and I have to manually change it in the scope from "All of type posts " to "Current page". 
      Is there a way to fix that? 
       
       

    • richardjacruz
      By richardjacruz+
      I'm building a website in a dev environment at http://162.144.182.17/~uescocra.
      I want to import a bunch of products, and then have the products have a different template than the default template. 
      I also want to change the default template for blog posts.
      Before I go making changes, can I do this where the post type of "products" has its own global template, and the same with blog posts?
      For instance, in a product I might want to have a widget for categories, similar products, etc., and in the blog I may want list of the latest posts, blog categories, link to an email sign-up landing page, etc.
      Thanks.
      Rich
    • abuzzelli
      By abuzzelli+
      Is there a shortcode or a way to automatically pull the site name into the footer or elsewhere?
    • casseysdesigns
      By casseysdesigns+
      In the past I would use nextbox for this task. However, Platform 5 does not have nextbox. I will do my best to describe what I am trying to do.
      I am creating a template for coaches, each product has its own link but they all share a common coach id. I want to set up the templates with the links for each product with a variable for the coach id so that I can change the coach id for all the links on the site by just changing the value of the variable $coachId. To do this I'll need to do something like the following...
      <a href="salesite.com/productcodes/referringRepId=<?= $coachId ?>" target="_blank">Product Purchase Link</a> Is it possible to do this with Platform 5?
×