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

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

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

Share this post


Link to post
Share on other sites
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

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

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

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

    • jeomiland
      By jeomiland+
      Hi guys
      Hopefully an easy question. I have some custom code included in a Next section in a DMS site that I'm converting to platform5. What is the easiest way to insert my code into a "section" which I can easily add to my page structure with the platform5 page editor? I have the Embed extension but that takes javeascript, and my PHP test failed. Also have the Shortcodes extension, but looks like that only inserts objects into the WP-loop? and again, how to create a Hook that can go here?
      thanks...
    • KathleenAspenns
      By KathleenAspenns+
      I would like to upgrade my site to PHP 7, but there is an error warning in the PL Framework theme. I should think this should be fixed asap, I cannot be the only person trying to be up to date.
      1976 | ERROR | preg_replace() - /e modifier is deprecated since PHP 5.5 and removed since PHP 7.0
       
    • Dan Haddock
      By Dan Haddock
      DMS: Latest Version
      Running a Child Theme
      Wordpress: 4.8.3
      Plugins:
      Akismet Anti-Spam 
      Coming Soon Page & Maintenance Mode by SeedProd
      Contact Form 7
      Cookie Law Info
      DMS Professional Tools    
      Enhanced Media Library
      Flamingo
      Google Analytics for WordPress by MonsterInsights
      Google XML Sitemap    
      Jetpack by WordPress.com
      Legull
      Loginizer   
      MailChimp for WordPress
      PageLines Updater
      Really Simple SSL
      Schema App Structured Data
      Sucuri Security - Auditing, Malware Scanner and Hardening  
      Uber reCaptcha
      Yoast SEO
      Problem Below
      Hi Team,
      I am looking to style the Continue Reading Button with the PHP you provided in an earlier ticket here: 
       
      I put the PHP code into my site, however I do not get my Icon back, I just get back Read More >>
      I have attached a screenshot of the code in place on my site along with the output.
      Interested to know what I may be doing wrong? - I am very new to PHP so a bit apprehensive on this.
      The Images: https://drive.google.com/open?id=0B0i4JJXa2jdQN2xoakZNRUdmaU0
      Let me know if you need any more information from me.
       
    • 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? 
       
       

×