Page specific menus in Wordpress - php

I am trying to make a page specific menu in Wordpress, where each page has its own options... The link is http://dev.activenation.co.uk/leisure-centre/southampton-water-activities-centre/
As you go through the "Your Centre" pages, the grey menu changes. At the moment, we are using conditional if statements to load the specific menus, however, the client will need to add more leisure centres.
Was just wondering if there was a more time saving way of doing page specific menus, instead of coding conditional if statements?

Add a custom meta box to the 'page' content type that is a simple <SELECT> list of all of the custom WordPress menus. On save, pull the selected menu ID from the SELECT list and save it to the database. On the page template, check if the saved value exists and if it does, pull in the WordPress menu that has the saved ID.
This will allow an editor to create any number of menus, pick a specific one for each page, and share like menus between pages.
There are a lot of tutorials and code snippets around creating custom meta boxes, and displaying a simple select of the available menus. If you haven't done custom meta boxes before, this is a good intro project since it only has one form field and it's easy to validate the data.
Smashing Magazine has a great walk through on custom meta boxes: http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

If those Centres are subpages of "Your Centre" you could try to use this plugin which creates hierarchical pages / category / taxonomy lists.

Related

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!

How to create single-custom.php for different repeater fields (using Advanced Custom Fields) in Wordpress

I'm using Advanced Custom Fields Pro with Wordpress 4.1.1
I feel like this should be pretty easy but I've been struggling with it.
The example I'll start with is I have a "Team" page that has a repeater with:
Profile Image
Name
Job title
Short biography
Email/social link
All as sub_field
I have everything working nicely in the page where all posts are display (the actual Team landing page) but I can't figure out how to get content for each employee to live in a single-custom_template.php with a permalink.
tl;dr I want my repeater content to be able to navigate to a single post/page with it's own custom template. Click on "Dave" in the whole team page have it navigate to his bio page.
I think you would benefit in building a custom post type for "Teams" so you're not selecting a new custom template (single-custome_"".php) each time you post another team member profile. This way also allows you to have all your custom meta fields organized under a single custom post-type. However, if you don't want to go through all the trouble in creating a custom post-type, you can post each single team member page as a child page to your parent "Team" page, so that the url would look something like, "yourdomain.com/team/team-name, and then have all your custom meta fields auto populate when you select the single-custom_template.php in the "template" dropdown field.

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.

How to colour wordpress menu lis based on category assigned to each page?

I would like to create a nav menu that displays all the pages of a wordpress site, its layout similar to what you would see in a footer sitemap layout, approx 5 columns with all the pages shown. Each page will be a project. I want to use wordpress category checkboxes (like you have for posts) to allow selection of one relevant category for each project page. Each page will then show a category caption below the project's description text, this I will style with CSS so each category has a different background colour.
Because Wordpress doesn't provide categories for pages, I have found a plugin to add this category feature to pages called ninja-page-categories-and-tags: http://wordpress.org/extend/plugins/ninja-page-categories-and-tags/
It's possible to edit the plugin php code under basic-functions.php to return a 'class' for the category displayed using get_slug and then applying css for each.
My problem is that on the menu, which will be a secondary menu in Thirty Ten displaying the pages, I want to be able to colour the background of each link to match the category that has previously been assigned to each page using the ninja plugin. Because the menu works with pages and the categories are not directly linked to the menu items (firebug will not show category details in the html of each link to reference with the css) I am wondering how I can colour each link based on category? Any ideas?
Ultimately what I would like to achieve is a grid of page links that are all coloured based on their category, a colour coded menu.
The plugin uses the standard wordpress category functionality but I just can't think how to connect these category details to the menu items to allow me to style them with css, any help would be really appreciated, even if just a point in the right direction.
Thanks
It's difficult to understand exactly what you're after, but essentially if you want to add extra classes to menu items (which will allow styling), you need to create a custom walker function.
Have a look at a tutorial like this: http://wp.tutsplus.com/tutorials/creative-coding/understanding-the-walker-class/

Categories