Wordpress - using advanced custom field plugin for a template file - php

I'm using ACF for a Wordpress site for the first time. I have a template file that I use across a number of pages - topimage-agency.php - and I need to make a paragraph within it dynamic.
I've created the custom field using wysiwyg editor and selected the main Agency Page -
Obviously I haven't set the template up with its own page so I've had to select one. The code is dynamic on the agency page and all works fine however it doesn't show/work any differently on any of the other pages. Is there a way I can make elements of a template dynamic using ACF or any other way?

You need to select Page Template instead of page. Then You Select Page Template name instead of page name(AGENCY).
If you do like this, your custom field will appear all the pages where you specify that template.
Hope this helps to you!!!

Related

How to have custom page template in wordpress

I developped a theme for Wordpress for one of my client and in that order, I created multiple pages in html for the moment. Except my index (static homepage) using the "single" template I think, I have other pages (each one is different and using different style CSS).
Is it possible, and how should I create and name the custom PHP pages in order to get each page displayed by its own html basis and styling?
Didn't find any matching answer on the internet yet, just general stuff about pages in wordpress, not custom ones.
Thank you a lot by advance if you can help me!
Separate php file for each webpage
Name each php file what ever you like, it does not matter
Add a template name at the very top of each php file
/*
Template Name: Unique Name
The template is for ....
*/
Open the wordpress backend with wp-admin and press create new webpage. When creating the new page select the template name you want.
Done !
It is hard to completely understand the problem. I notice you have .html theme and you want to use this template as page template. In this case you have to create a file in the root of theme with name: cutome1-page.php and this file needs to start with the following line:
<?php /* Template Name: Custome1 Page */ ?>
after that, while you create page in wordpress panel, you see a template as : Custome1 Page

How to make a dynamic wordpress page (custom control/page template box)

I have completed numerous wordpress template tutorials focusing on implementing multiple pages, and a custom dynamic navigation. The only issue I have is finding a source on creating a custom template box. For example, my goal is to customize the page template box following the mock up. The content placement is done in php, and designed in css. That way I dont have to add content in php but instead add it in wordpress based on my custom design. I have not found any source to achieve this. Does anyone have a source that displays how to create custom template boxes(the dynamic part)?
Links below is what I used to create my wordpress site
https://www.smashingmagazine.com/2013/05/migrate-existing-website-to-wordpress/
custom navbar for wordpress using bootstrap
I tried another source called Dynamic Page Templates in WordPress, Part 2 which suppose to explain how to create custom controls/template boxes. Following the link was unclear, resulting in not achieving the goal.
Thanks,
There are many ways to create a dynamic page in WordPress. I am sharing one of it. Install Advanced Custom Field Plugin and read its documentation. It allows page content to be changed from back-end (Its great for text/images). For areas where you want to user to choose whatever custom widget she wants to choose, add a widget area following any custom widget tutorial.

Allow page text to be edited from inside the wordpress menu without hardcoding it

New to WordPress theme design, and my google searching is not returning what I am after.
I have a theme I have created and its fine, but the text is all hardcoded into the theme.
I want there to be options in the theme appearance settings? (right place?) where a user can e.g. enter their 'about us' text.
But I have no idea what I should be searching or how to pull in that information into my theme.
Im no a beginner to PHP, but just the way WordPress works itself.
A link, search term or quick start is all I need.
I think you might find the (Free) Advanced Custom Fields plugin useful: http://www.advancedcustomfields.com/
You can add unlimited custom fields and create user interfaces for non-technical people to add content to your theme without them touching any code.
If you set up a field named 'about_text', calling it in your theme would look like this:
<?php the_field('about_text'); ?>
First, you should learn how wordpress is working to display the content. In back office, under Settings > Reading you'll find an option that let you tell how you want Wordpress to deal with the front page : is it a listing of the posts, or a static page?
If you choose the first options, it will use the index.php template from your theme folder. If it's a static page, you'll have to select which page to use for displaying the home (a page you created under the Menu page). The template that will be use then is front-page.php.
For every post / page (page is a post_type, just a variation of post) there will be a title field, a wysiwyg content and a featured image which will be displayed in a template. That's all you can manage by default. To display the title you can use the_title, the content the_content and for the featured image you will need the_post_thumbnail - note that those functions will need to be used inside the loop.
In order to display some more fun, you have many tools at your disposal:
Widgets : widgets are displayed in a sidebar - don't take it literally, it's just a zone of your template. You can register a sidebar with register_sidebar (use this inside your functions.php file, within an init hook). Then in your template you can display the sidebar with dynamic_sidebar.
In WP back office, go then under Appearence > Widgets. You will find your brand new sidebar where you can put any kind of widget you want. If you need a wysiwyg widget, I recommend you to install the Black Studio TinyMCE widget.
Custom fields : any post_type (a post type is an entry in wp_posts) in Wordpress have some associated metas store in wp_postmeta. A meta is defined by a key and a value - it's like any post have an associated array that you can customize.
There is two ways to work with custom fields. First, you can use the default Wordpress feature: when editing a page, click on the screen options button on the top right and enable "custom fields". You will now have a new area to work with on the bottom of the page : you can add fields by name (by default it will list the existing fields names but you can add your own) and value. It's good enough to simple text fields. Then in your template, you can get that value with the get_post_meta function.
The other way is to use a custom fields plugin, which allow you to have wysiwyg fields, loops, media uploader, datepicker... Two popular plugins are Advanced Custom Fields and Custom Field Suite. They both allow you to easily create set of fields for any page / post_type from the back office, and provide their own functions to manipulate fields in templates (but you can still use the WP functions if you want). For example, to get a custom field with Custom Field Suite you do: CFS()->get('my_custom_field').
Custom Post Types : sometimes, custom fields and widgets are not really convenient when you deal with a lot of data with possibly associated pages. In that cases, you can create your own post types just like posts or pages, but you can define which capabilities they have. Use register_post_type to define your new post type (still in init hook), that will make a new section available in your back office, just like posts. Then in your template you can query them with get_posts, the WP function that you will probably the most use when you'll start to play with Wordpress. I suggest you to read the WP_Query documentation in order to learn more about it.
And, at last but not least, you can create your own template that you can associate with any pages. For that, create a php file named whatever you want in your theme folder, paste into it the content from page.php and add this PHP comment on top :
/*
Template Name: My Template
*/
Then choose this template in the dropdown when you edit a page (on the right sidebar).
I think you will have enough to play with, but if you want learn more I recommend you to read about Wordpress hooks and the Widget API to create your own widgets.
Have fun with Wordpress!

Unique fields added to Wordpress Pages editor

I need to customise the page editor in Wordpress so I have 5 text fields which I can pull out in the front end page. This is because the Wordpress manager is a bit hopeless with no HTML skills and the content of these boxes will populate buttons and a drop-down select. These fields will be completely unique to the page being edited. How do I go about this? Do I need to build my own plugin or customise an existing one or other?
Advanced Custom Fields is a great plugin for this. You can target a particular page to display fields on and then output your fields in the front end templates using:
the_field('field_name');
See here: http://www.advancedcustomfields.com/

Displaying Custom Content On Different Pages All Using The Same Template

This is my first Wordpress build so bear with me whilst I try to explain the issue.
I'm building a site for a hotel. 3 of the pages of the site all feature the same content (a heading, a paragraph of text and a gallery) and all feature a 'box', the content of which differs slightly from page to page. For example, on the 'accommodation' page the box will simply have paragraph text in, but on the 'restaurant' page the box will have links to downloadable PDF menus.
I've built a custom template file for these pages called 'standard-page'. My question is, what would be the best way to tackle this box issue? I'm guessing there is an easier way than creating a separate template for every page? The box does need to be content editable, so for each page the backend fields will differ (the restaurant page will require a file upload facility for example).
I've been following a Treehouse tutorial so far, but this isn't really covered in it. I've been using Custom Fields if that helps.
The only idea I can think of is having the box as a separate file (e.g. content-box) and having a WP_Query which calculates and displays different fields based on the page.
Here is an example of the different style boxes. The one with the offer is for the homepage.
using a content-box.php would probably be your best bet and inside it - target the pages by name.
inside of the content-box.php:
<?php if(is_page('accommodation')) {//show accommodation box}?>
<?php elseif(is_page('restaurant')) {//show restaurant box }?>
etc.

Categories