Adding custom post title to wordpress menu - php

Excuse my rookieness – this might be a very simple thing to solve for someone with more experience. I tried searching the forum but did not find a fitting solution.
I am trying to make my Wordpress menu add the custom title to a current menu item on a specific post type when that page is active, what would be the best way to do so?
Menu <--- Original menu item<br>
Menu: Addition <--- When on the custom post type titled "Addition"
Any ideas?

I would start with finding the code in the template ( theme ) where menu is being rendered. You need to look for function that renders navigation menu wp_nav_menu():https://developer.wordpress.org/reference/functions/wp_nav_menu/
Depending on how complicated solution you want to choose to pick for checking the post type - I would suggest simple if() statement.
To check post type you can use get_post_type():https://developer.wordpress.org/reference/functions/get_post_type/
If post type is "Addition" pass argument to wp_nav_menu() to use custom menu prepare for that post type.

Related

Add new field in WordPress Menu to output in theme

Is there a simple class or function to extend the WordPress default menu items with new custom fields?
For example, when you go to Appearance - Menus, add a new menu and drag/drop an item to your menu, that actual item has few hidden fields that can be enabled from Screen Options:
Title Attribute
Description
My question is: how to add another custom field there? Like a background field to write the text there and output it in my custom theme like we output the title and description:
<?php echo $navItem->description; ?>
Changed the html code live on the admin page, so you can catch my idea on what I want to do.
Thanks!
ACF is the plugin just what you looking for. Create as many fields as your want, assign it to manu form and you are done.
For more information follow this URL,
https://www.advancedcustomfields.com/resources/adding-fields-menu-items/
Hope this helps.
follow this URL may help you
Adding custom Fields to WordPress Navigation Menu Items
http://jafty.com/blog/how-to-add-custom-fields-to-wordpress-navigation-menu-items/

To create custom the wordpress template with both the static and dynamic mixed

I am trying to customize the wordpress template.
In that template the content will be both static and dynamic.
Images, color and button will be static.
All other content will be dynamic.
What I am trying to do is that if i change button name or color in that template it should affect is all place in the sites.
I know about the the_content() I don't know whether split will work.
But is their any to do this process in the form of template.
For Example see the image here
Please need help.
Thank you in advance.
for having dynamic content on your website you can use custom fields..
you can either use the Wordpress built in custom fields or a very good plugin Advanced custom fields (ACF) ..
explanation can be lengthy but you can refer to below documentation and actually it is very simple..
https://codex.wordpress.org/Custom_Fields ( For WP built in Custom fields)
https://wordpress.org/plugins/advanced-custom-fields/ ( for ACF plugin )
Hope this helps
Take care and happy coding
If you just want your first title dynamic, then you can fetch data title from your page like with
the_title();
And all your remaining data will be static in this way you can get your layout easily ... as far as your button pop up message concerned, you can use jQuery to achieve that and can show any of your message. Hope that solves your issue

Wordpress custom sub template, Template within template

I have a custom post type defined in Wordpress. Please look at the following image(not my work just used for reference):
For each of the posts within the custom post type I would like to define 3 sub templates that can be chosen from within the WP admin:- Content left, Content centre, Content right. When they are rendered out within the loop (not single page) the output would be similar to the above image.
Can this be done in Wordpress? If it can please can you help point me in the right direction?
Many thanks in advance.
You can use custom fields to give the three parts content. Custom fields can only handle plain text so you can also use Advanced Custom Fields to add a ritch .

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!

Wordpress Display Content in Sidebar on Specific Post/Pages

I am not sure exactly what I am looking for in the api so I'm going to ask here. On a post/page, I want the ability to have a piece of text display on the sidebar ONLY that content. The content to be display is to be set as an attribute or something similar in the edit area of that post only.
Is there a way of doing this and where do I look in the api?
Using a text widget as already mentioned, you can use the Widget Logic plugin and use an if statement to display that widget only on the post you want.
http://wordpress.org/extend/plugins/widget-logic/
If you are looking for logic to do this here it is:
In your post you have access to custom variable so create one which you will then access in sidebar and if that is true then a widget can be shown else it does not need to be.
You need to access this custom variable outside post loop which you can use by using global variables and assign its value to that.
In your widget you need to look at globalvariables and check the value of above and then do your if else logic to show or hide parts of content in sidebar.
A good starting point for this can be this tutorial which does show twitter or facebook posts based on custom variable on post.
You can use this plugin and either select pages, post-types or even a comma separated list of post ids http://wordpress.org/plugins/display-widgets/

Categories