wordpress. Is it possible to have dynamic content? - php

Is it possible to have dynamic content in wordpress? I know that navigation, footer, and sidebar is dynamic. But what about the content? What if my content is within a 3 col grid? How can I add a 3 col grid to wordpress if I am only provided with one paragraph box within editing page? If i add the html code in my php file, it will be static and not dynamic. I have studied resources and not found a solution. In result I am asking here to clarify. Therefore, how can I make the content within the body dynamic?
Some of the sources I studied
Nav Walker
Dynamic Template

It totally depends on your needs and the time you can spend on this. Here are some guidelines:
If you always going to follow a specific layout for a page then you can have meta boxes for the content and style is applied by default.
Examples:
Advance Custom Fields (ACF) is most popular and easy to use. Alternatively, you can create custom meta boxes.
If you wanted to give more control then you can create your own layout snippets and define as shortcodes.
Examples:
In one of my recent project, I create my own shortocodes and that can be used in any page and will be automatically formatted before displaying on frontpage like
[video_right]
[testimonial]some content[/testimonial]
[one_fifth]columns[/one_fifth]
BTW, you can also use any visual builder like Visual Composer etc.

Related

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!

How to output html on a custom location with a wordpress plugin?

How can I use a self-made Wordpress plugin to output for example a custom menu or custom HTML to a specific location? The only places I managed to output content is in wp_head and wp_footer, but is it possible to get content to show up anywhere else? Is it even possible to force the plugin to output the HTML for example inside a specific div or a DOM element?
Example scenarios
I want to add a custom button that triggers a menu or modal, but the button needs to be located inside the header and I also need a place for the modal HTML before the footer (example).
I want to add custom made "social share buttons" to every page and need a place to output the HTML after the page title.
Just to give you a feeling of what I'm trying to do...
Maybe I'm just way off track. I am new to this, but I am eager to learn.
"Teach me the ways of the force"
Appreciate any help, Thanks :)

Widget or Plug-in? Building a theme and unsure how to approach optional content

I have a question regarding how best to build a widget/plug-in for WordPress.
I have tried to code this thing out but unfortunately to no avail but that's because I'm increasingly thinking I'm going about it the entirely wrong way.
This is what I'm trying to achieve:
I have built a theme from scratch. In this theme I have two content areas. The larger of the two contains the main content and the smaller of the two (proposed widget/plug-in) contains supplementary information (opening times, Facebook feed). I don't want this widget/plug-in to appear on every page and would like the ability to turn it on or off within the usual WordPress admin area.
The impression I am getting is that I can build the widget that contains the content I want (with necessary forms to change said content) but it is either on for ALL pages or off for ALL pages, no sort-of page specific functionality. That's where I'm thinking a plug-in would extend the functionality and allow me to be more page specific with it. That is my current set-up with a theme I'm running and plug-in I added (neither of which were coded by me) but I would like to repeat it as best as possible.
Would it be right to assume that widgets are not really designed to have page specific functionality and that function should be left down to a plug-in?
I appreciate this question asks nothing really in the way specific advice but I would just like an opinion or two on the best approach before I go away and create it - this is my main struggle at the moment.
Thanks for looking.
This can be done with the Jetpack plugin. Once activated you can choose what widgets display on what pages:
The Widget Visibility module enables you to configure widgets to appear only on certain pages (or be hidden on certain pages) by using the Visibility panel.
Visibility is controlled by five aspects: page type, category, tag, date, and author. For example, if you wanted the Archives widget to only appear on category archives and error pages, choose “Show” from the first dropdown and then add two rules: “Page is 404 Error Page” and “Category is All Category Pages.”
Originally posted here
It is also possible with the Display Widgets plugin.
This is a common problem. The usual remedy is to use an existing plugin that allows widgets to be tied to pages.
The 3 most popular plugins for this are:
JetPack
Per Page Widgets
Widget Logic

easiest way to mix page content with template functionality in wordpress?

Im wondering is it possible to mix page content that the user can edit in wordpress with template functionality.
At the moment it seems I have to decide where the_content is going to go in my template and thats where ALL the users content goes.
But what if I want for example
some user content, then my own functionality from a template, then some more content the user can add in the page, then more functionality
Here is an example, the text highlighted in blue above the 4 boxes at the bottom is functionality. But ideally, I would like the user to be able to also change the 4 boxes through wordpress. But I was forced to hardcode those as Im already using the_content above that.
http://limerickfc.hailstormcommerce.com/academy/
There are more complex examples too, thast just a simple one
thanks
You can use Page Templates to run custom code and custom loops, and those four boxes fall perfectly into Widgets sections. Alternatively you can use Custom Fields to basically make anything possible in your page templates. However, it's quite difficult to make a sexy drag-and-drop content builder interface that does not suck. But doable. :)
Hope this helps. Cheers!

Categories