Jump to content

Archived

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

quinntinm

Adding php to PLNextBox error

Recommended Posts

quinntinm

Hi, i am adding a custom field to a page footer and want to add the php into the PLNextBox but am getting an error.

 

I have created the custom field in wordpress and named it "1kg_thrift" and added the following into the PLNextBox

<?php echo get_post_meta($post->ID, "1kg_thrift", true); ?>

When i save and preview i get a line in the PLNextBox that says "Looks like your NextBox PHP resulted in an error :/"

 

Can anyone assist me here?

 

Thank you.

Share this post


Link to post
Share on other sites
quinntinm

A quick update - if i check the checkbox "Allow PHP execution" without adding any PHP, i get the error

"Looks like your NextBox PHP resulted in an error :/"

 

Surely this is not correct?

 

 

WP 4.2.1

DMS 2.1.9.3

Share this post


Link to post
Share on other sites
Aires
Remove the php tags and see if you still get the error. I was told by Danny the next box doesn't accept php open and close tags so that might be the issue.

Aires


Sent from my iPhone using Tapatalk

ndTgvai.jpg

Visit iheartpagelines.com for the latest tutorials on PageLines related products.

 

Share this post


Link to post
Share on other sites
quinntinm

Hey Aires, thanks for the reply.

I tried that as follows:

echo get_post_meta($post->ID, "1kg_thrift", true);

But i still get the error message - "Looks like your NextBox PHP resulted in an error :/"

Would be great to get an opinion from the support guys on how to resolve this.

Share this post


Link to post
Share on other sites
Danny

Just added your code to the NextBox section and get no error. However, as I am not sure how you're creating your custom fields, I can not test it properly.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
quinntinm

Hi Danny.

I am using advanced custom fields.

I sent an email to them and they suggest that i use the fields option:

<?php 

/*
*  display a field value from the current post
*/

the_field( "text_field" ); 

/*
*  display a field value from another post
*/

the_field( "text_field", 123 ); 

/*
*  use the_field / get_field with conditional statements
*/

if( get_field( "text_field" ) ): ?>
    <p><?php the_field( "text_field" ); ?></p>
<?php endif;

I added my settings to a plnextbox

the_field( "1kg_thrift", 249 );

and checked the checkbox that says "Allow PHP execution" and the plnextbox does not display.

 

when i add it like this:

<?php the_field(  "1kg_thrift", 249 ); ?>

I then get this error:

 

Looks like your NextBox PHP resulted in an error :/

 

What am i doing wrong?

 

 

All i want to do is add 3 custom fields in the admin and have them display in the footer on all pages.

 

Thanks in advance.

Share this post


Link to post
Share on other sites
Danny

You can not use PHP tags in the NextBox section. Therefore, if you want to implement them using the code they have provided you will need to either use Hooker plugin or use a hook via your child themes functions.php file.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
quinntinm

Just added your code to the NextBox section and get no error. However, as I am not sure how you're creating your custom fields, I can not test it properly.

 

Hi Danny, what code did you add without the error?

If there is a way to add a custom field that i can display the contents of in the footer using plnextbox as you mentioned above please can you tell me how to do it.

I am happy to do it the way you suggest if it works as you said it does.

Share this post


Link to post
Share on other sites
Danny

When I added your code, I tested the code you provided, I didn't receive any error. However, it wasn't really a proper test as I didn't know how you were creating the custom fields.

If you want to include a custom field to your site, you will want to use a hook. You can do this via the Hooker plugin or via your child themes functions.php file. Unfortunately, we can not provide any further assistance as this type of customisation goes beyond our support scope.


Please search our forums, before posting!

Share this post


Link to post
Share on other sites
quinntinm

Hi Danny.

 

I understand the support scope, but it's a pity that more information cannot be provided because some of us here are not coders and are trying / learning to develop websites as best they can with the knowledge they have. (By that i mean me.)

 

If i had more to go on i could try and find out more on the wordpress blogs etc and i would hopefully eventually work it out. But it make take days and i might just get frustrated and give up.

 

If i was given some sample code with the advisory that it is not supported it would be a starting point i could try.

For example.

You need to add something like this "XYZ" to the functions.php page and then in your plnextbox you would need to add the following "ABC".

 

That would be more helpful.

 

Have a great day.

Share this post


Link to post
Share on other sites
Danny

Okay, we shouldn't be providing this code as I mentioned it goes beyond our support scope. However, if you want to get a custom field onto your site, I would suggest using hooks via a child themes functions.php file.

 

For example:

 

https://cloudup.com/cNO_lXb_2Su

https://cloudup.com/cqjn3ou7_-Q

 

Let's say you have a text field (called Boom) that you want to display below the excerpt of your post that is wrapped in a header tag (in this case h2), you will want to use the following code:

 

https://gist.github.com/Dannyholt/7c0f8aa352e9f728b638
 
Which will give you the following - https://cloudup.com/cBhoPl3Xidm
 
If you want to display the field without any HTML elements wrapping it, use the following instead:
 
https://gist.github.com/Dannyholt/05901499dd766156a53e

This will give you the following - https://cloudup.com/c6vJrBG4AoT
 
You can use this method as an example to add your own using the different hook locations. 
 
Simplest Method:
 
The simplest method of all would be to simply use the PowerLoop section and use the ACF shortcodes and some HTML to position your content and custom fields.

For example, if you use the following basic HTML grid and shortcodes for PowerLoop you can position your posts title, thumbnail, custom fields and excerpt/content with ease.
 
https://gist.github.com/Dannyholt/1b892a68619378a415bb
 
Which you will give the following - https://cloudup.com/isLDs55kiwX

Please search our forums, before posting!

Share this post


Link to post
Share on other sites

  • Similar Content

    • Lisa Haran
      By Lisa Haran+
      Hi 
      I have a map here http://www.iloveoffset.com/maps/
      I want to add several pointer locations to the map, but when I do they do not appear.
      On this map there are 2 pointer locations and as you can there is only one visible.
      Earlier today I added 7 and could only see 4 so there is something odd going on.
      My theme is up to date
    • clj182
      By clj182+
      Hello,
      I've been having trouble unlocking the template section for past couple of weeks. When I try clicking nothing happens. 
      I've deleted my custom css and removed plugins. Im down to having only the following plugins:
      Akismet
      Contact Form 7
      DMS Professional Tools
      Pagelines Updater
      WooCommerce
      It was working fine before i have no idea what's going on with it.
    • flourishdesignstudio
      By flourishdesignstudio+
      My DMS 2 site http://www.heart-stone.com/ will not save any new custom css... I can still edit templates and publish those but any custom css that I enter never saves.
      All WP files, themes, and plugins are up to date. 
      Any thought about what might be causing this?
    • flourishdesignstudio
      By flourishdesignstudio+
      Is there a way to edit the custom CSS via FTP? I know I can edit the custom code in the Chrome editor but is there a file path I can use to find and edit the CSS directly from our FTP?
      Thanks in advance for the help!
    • nizami
      By nizami+
      Using navbar section with correctly configured WP menu to display main navigation at https://elenaangel.com. 
      All fine in desktop viewport. Menu displays twice in hamburger mode. How to fix this please? 

×