I created a new template for a page.
<?php
/**
* Template Name: Sponsors For Homepage
*/
?>
<html>
<body>
<?php get_header('sponsor'); ?>
<div class='divone'>
<?php the_content(); ?>
</div>
<div class='divtwo'>
<?php sponser_advertisement(); ?>
</div>
</section>
</body>
</html>
And I added a new custom field for the template. Using the Advanced Custom Fields plugin 4.4.8
I made sure that the field would show on the correct template:
The fields showed up on my template page
For some reason the field value "This is the new field" does not not show up when I preview the page in my browser.
Thanks in advance.
Suggestions?
This is the wrong way to display the custom field value.
If you want to display custom field values in your template, using Advanced custom fields plugin you have to use functions like these:
<?php the_field('field_name'); ?>
or
<?php echo get_field('field_name'); ?>
you can find full documentation on working with ACF values in here:
ACF Documentation
Related
I am developing a custom theme in WordPress, and am trying to put custom HTML and PHP in my home page template. Whenever I am posting code for divs or custom fields in my home page template, they are simply not rendering and displaying on the front end. In the example below, the <div class="col-full"> is not being shown on the front end.
<?php
/*
Template Name: home
*/
?>
<!DOCTYPE html>
<?php get_header(); ?>
<center>
<div class="col-full">
<?php get_template_part( 'content', get_post_format() ); ?>
</center>
<?php get_footer(); ?>
Looking at your code, you've set it up as a template file. These need to be manually selected from the page as the template for it to work.
I'd recommend consulting the wordpress template hierarchy https://wphierarchy.com/. This shows you which files will try to be loaded based on what page you're visiting.
If you're still having trouble, i'd suggest installing the plugin https://en-au.wordpress.org/plugins/query-monitor/, which will tell you the template being loaded as well as other handy information.
I was wondering if there is a way to add hidden shortcode to every Woocommerce's product post? And how would I do that?
Shortcode is: [customer_list]
Thanks
This should do it for you:
<div style="display:none;">
<?php echo do_shortcode('[customer_list]'); ?>
</div>
You can use <?php echo do_shortcode('[customer_list]'); ?> within the div wrapper if you are editing the content-product.php template or any other that is used directly on the product page.
I'm using wordpress as a backend to my website, and trying to use foogallery as a gallery for my client to upload their own images to.
My problem is that I've made the gallery in wordpress, connected it to my index.php through , but for some reason my gallery simply isn't working. Instead I just get a page that looks like this
If I click the images they bring me to their own page with just the image on it, instead of getting the lightbox plugin associated with it.
Here is the code on my index.php
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<div id="main">
<div id="content">
<?php echo do_shortcode( '[foogallery id="33"]' ); ?>
</div>
<?php get_footer(); ?>
I have a custom wordpress post.php, all posts within a specific category will use this template. In nearly every post there will be scrolling testimonials, to handle this I am using a layer slider.
Within the page I have a custom field of testimonial that is filled with something like [layreslider id="2"]
In my php file I have:
<div class="trips-testimonials">
<?php do_shortcode(get_post_meta($post->ID, 'testimonial', true)); ?>
</div>
This seems to do nothing. If I add echo to the PHP:
<?php echo do_shortcode(get_post_meta($post-ID, 'testimonial', true)); ?>
I get the output of [layreslider id="2"]
Here is a sample page, the blue box under the photo is where the slider should show up.
http://www.ct-social.com/ctsdev/aff/capri/
Thank you very much for your help.
looks like you miss the > from post Id so it should read
<?php do_shortcode(get_post_meta($post->ID, 'testimonial', true)); ?>
Also you may need to call global $post; if outside the loop.
I wish to add a custom page to wordpress, not in the usual sort of way. This page has my own custom script and functions and to develop a plugin is beyond my means so I was wondering if this is possible:
Suppose I were to build it on the existing page.php script in my there folder, my script looks something like this:
<?php get_header(); ?>
<div id="left-area" class="clearfix">
<?php
//My script would go here
?>
<div class="comments">
<?php comments_template('',true); ?>
</div><!-- end of comments div -->
</div><!-- end of left-area -->
<!-- LEFT AREA ENDS HERE -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Is this even possible? I tried and got a page not found error. And if so, how do I call this script assuming WP is installed in the root directory? Example: www.mysite.com/myscript
Absolutely. Duplicate page.php. Rename it to template_mine.php. Open to edit, and before the get_header tag, add:
<?php
//
// Template Name: My Custom template (choose something more descriptive, like contact page)
//
?>
Go to Wordpress dashboard for pages, create a new page with your title, and in the Page attributes on the right hand side, under templates, select your template name, update, and you are all set.
Reference: http://codex.wordpress.org/Pages#Creating_Your_Own_Page_Templates