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/
Related
I want to break single WordPress post into multiple pages and i know that i can simply achieve this using wp_link_pages function but unfortunately it's not working for my custom post types. For custom post types it's generating the links but when i click on the link nothing happen.
I have tried to find out the issue but did not got any clue. Is i have to do anything extra for my custom post types to use wp_link_pages function?
You can use the following single code in the position you'd like your content
split.ensure that you are writing the code in the "Text" display editor
rather than the default "Visual display editor(note the two tabs displayed towards the top right in the editor)
<!--nextpage-->
top right of your post or page editing screen)".
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
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!
I want to show the full post with comments and author box on the home page just as if the actual link to the post was clicked. I will set the canonical on the actual post to point to the home page for seo purposes.
I've seen some code out there, but so far nothing that matches my exact needs.
I only want to display 1 WordPress post on the homepage with the comments and author box below the post. And I want to be able to specify which post will be the one that gets displayed on the homepage. (which post id#)
To add to this, I also need the rel="author" to be visible in the header section. I'm using WordPress SEO by yoast and have selected to not show rel="author" for pages. And all code out there I've tried that shows a single post on the home page treats it as if it is a page instead of a post, therefore removing the rel="author" from the head area.
Please do not reply with how to set the number of posts in the Reading tab or how to set a static page. I already know that. That won't work for my needs.
In summary, when I go to my home page I will see the article I wrote along with the comments and author box below it and rel="author" in the header.
Your best bet would be to set your homepage as a static page, and build a custom template for that page. In the editor, create a custom field that allows your to select a blog post to feature (look into Advanced Custom Fields plugin for easy custom fields), grab that custom field value, and use that to build either a WP_Query, or just call the various bits of information using the ID of that post. The trickiest part is getting the_content() by ID. Here's how you can do that:
Add this function to the functions.php file:
function get_the_content_by_id($post_id) {
$page_data = get_page($post_id);
if ($page_data) {
return $page_data->post_content;
}else{
return false;
}
}
Call your function in your page template like this:
echo get_the_content_by_id([INSERT YOUR DESIRED POST ID HERE]);
If you make a php file in your Theme directory called front-page.php, that will automatically appear as the template for your static home page.
Now as far as the rel="author" thing, I don't know anything about that, so I unfortunately cannot help with that.
Also, I'm unsure why my code is losing it's formatting here.
Right now one this certain ACF is only displayed on the user end of the relevant page where generated ACF editor appears.
What I want to do is make a 'global' ACF, featured in certain php include that will appear on most of the pages in my template.
How do I achieve this?
The only way I can achieve this effect is disregard my include, recode each page where I want that global ACF to appear, and then make sure ACF editor appears on each page in wp-admin, which isn't very graceful.
Thanks in advance.
I also had the same issue too. If you still need a solution (or for those who still need an answer) ACF have released a premium add-on called "Options" ACF Options.
This will allow global use of custom fields. Check out the video tutorial on the page to customize the sidemenu for grouped global content.
<?php the_field('field_name', 'option'); ?> will call the content of that particular field.
I hope this helps.