WordPress multiple content sections - php

Alright I am completely lost on how to do this so I am just going to throw the question out there and hope somebody can help me in some way or another.
WordPress offers the option to create custom Taxonomies so I got the idea of pulling something out of my hat and creating a custom content section apart from the content section wordpress currently offers.
The website shown above is the only website I have been able to find which currently does this and is on a WordPress platform, as you can see they have the SoundCloud audio player pushed over to one side with the actual content placed to the other side creating that flawless look.
I guess the question here is how can I turn <?php the_content(); ?> into something completely custom pulling from a completely different form in the back end so the same information is not shared.

There are numerous ways to achieve what you want.
Shortcodes
Custom page templates
Custom meta fields to store values like the soundcloud embed url, to afterwards use it in your code.
You can always also enter HTML in the page editor, but for obvious reasons not recommended.

Custom post types allow you to define a new type of content. It will have its own section in admin where you add and edit data separate from normal Wordpress posts. It can have its own templates allowing different layouts, and you can set up custom fields so that it can store different data.
I also recommend taking a look at the Pods Framework. This plugin allows you to define custom content types very easily in the admin interface. You can set up all your fields and data types from there. All that's required then is to create the templates to make it look nice.
The nice thing about these approaches is that while the data is kept separate from standard Wordpress posts, you still have the same familiar UI, so it's easy for none-technical users to update the content.

Related

What is the best way to create page in Drupal 8 so that I can then add these posts with images?

I have a Home page on the Drupal website (such as is created after installation), but I still need to create this page:
What is the best way to create a page so that I can then add these posts with images?
I am just starting to learn Drupal and have heard so far about such ways of creating pages:
1) in admin toolbar: Content / Add Content / Article
2) in admin toolbar: Content / Add Content / Basic page
3) in admin toolbar: Structure / Views / Add Views
Which one should I use? Or maybe there is some other option that I don’t know about?
P.S. At the moment I am more interested how to create empty page on which I can then add posts later, and adding posts it is another question.
Welcome to Drupal.
Drupal ships with the default theme which won't look nice but it does its job in the right way. Now if you want to create a better UI/UX obviously you should create a new theme. But before that make sure to read and understand the concepts behind Drupal. Drupal docs are your first friend.
Drupal Documentation
Drupal considers everything as nodes and that's how Drupal got its power. As you mentioned, Articles, Basic Page etc are called content types and they can be used to create a particular type of content.
Now for your purpose create a new content type and add the fields you need. From the image above I can say your content type needs Title, Image, Category and Date. After creating content type you can create as many contents as you want under the content type you just created. Consider each card in your image as content.
Now you can use a Drupal Core Module Views, to perform DataBase Operations without writing single code. Yes, you can select fields, sort, order etc with Views UI and display it in a page or a part of a page (Block).
I would say just try this out in the default Drupal theme and when you understand how this works, you can start creating your own theme for your project.
Theming Drupal
There is a lot of resources available. But you have to make sure what you are asking is whether you actually need. It will take some time, but it worth.
To build layouts for homepages on Drupal 8 you best friend is https://www.drupal.org/docs/8/core/modules/layout-builder
To build the content blocks inside your home page, you should start creating nodes on a node content type to hold your information. For instance: news content type, with a title, a body, a date, and an image.
For every node type, ex. news, work on the preview display, full display, and any other display which makes sense. These displays can be used later in the Layout Builder directly or in Views, referenced below.
If you wish your list to be dynamic, such as the last 10 entries are shown first, then use a view to hold the content sorted and filtered as you need.
In a nutshell.
Create a content type for your article/news.
Modify the displays of the content types to have at least a summary and full view.
Create the content itself to have something to see.
Create the view (block) to filter and sort your content.
Create a page layout (this makes sense for landing pages) which places your new view and any other content you need in any disposition.
This is roughly what I would do. The steps described above contain many intermediate steps. If in doubt, check the docs.
I hope that helps!
First, decide what will you display on that page. Is it content in some existing content type (article maybe) or you want to crate new one for this purpose.
If you need new one then create it (Structure -> Content types -> Add content type).
Then check what fields will you need. I.e. image, some description text. Add missing ones.
Create few nodes (pages) in that type so you could work with them.
Then for displaying you should crate a view (Structure -> Views -> Add view). It can be a page view (you are displaying only that content on page) or block view (this is just a block among some others). If you create a page you could visit it and if you create a block you have to add it to some region to appear on page (Structure -> Block Layout).
Inside your theme you should create templates for this page/block. Turn on twig debug mode so it will show you hints - what templates are used and how can you name yours to override default ones.
Adjust CSS to make it look like you want it to look.
Find some tutorial(s) for the details
Previous answers have given the flow of the work you should go through, I would like to add some resource that might help you achieve this.
Creating content type and fields: https://www.drupal.org/docs/administering-a-drupal-site/managing-content-0/working-with-content-types-and-fields
https://www.drupal.org/docs/user_guide/en/structure-content-type.html
View and View modes: https://www.drupal.org/docs/user_guide/en/views-concept.html
https://www.drupal.org/docs/8/api/entity-api/display-modes-view-modes-and-form-modes
Handling block of the view: https://www.drupal.org/docs/8/core/modules/block/overview
Feel free to ask if any further explanation is needed.
Thank you

How does WordPress Dynamically Generate Pages?

I'm new to web building and programming and what not, but I'm trying to create a website with a lot of pages. Note that this is pages not posts. The pages will use the same layout, but the content will be different. It's very inefficient to create the pages in Wordpress. I was wondering where does Wordpress store the database that is used to generate the pages. I figured I'll just add information to the data base - which would be much for efficient.
Any ideas on how to do this? Or other ways to create many pages efficiently. I would love to be able to work with Excel or some other text software, rather than the slow Wordpress platform.
Thanks!
All content are saved to the wp_posts table in your WordPress database. whether its for pages or as posts. Databases are provided by your webhost. Edit: Excel is not a web authoring program, nor should it be used as one.
You should put your header in header.php and footer in footer.php, and main content if it's not post type in page.php or you can make you custom page template, also if you are use page and not post, don't forget change it from settings
You can't use Excel for your data. You can only use the Wordpress Database or external files.
As stated above, pages are stored in the posts table.
Since your data isn't actually dynamic, you should probably go ahead and create individual pages and create a template to display the pages the way that you want them to look.
https://developer.wordpress.org/themes/template-files-section/page-template-files/
For the record, you can use a single page to output different content. Most shopping carts, for example, are displayed using a page called 'Cart' (or something similar), but the output is different. The Events Manager plugin outputs events to a page called 'Events'. This, however, is for truly dynamic data and not what you are looking for.

populate Wordpress page/post from external db - on the fly

After providing an event calender with PHP/MySQL/HTML/CSS I want to use Wordpress for that project from now on. Account and data management will remain outside of wordpress scope.
My best idea so far is to populate the posts (or pages) entirely from the already existing db. The URLs would be created by apache's rewrite engine.
To use one post and populate just the content would lead to really bad SEO.
So I want to create (virtually) unique posts populated entirely from the db. Extensive research on that topic brought up nothing usable so far. Maybe someone could point me in the right direction?
Preferences:
using mod rewrite to create the pages urls from event /ID/title rather than using the timestamps to create posts
keeping the data editable via external admin panel (no copying into WP-DB)
head data of post / page must be populated from db, e.g. title, author, timestamp etc.
Suggestions would be much appreciated, thanks in advance.
Have you tried the plugin WP All import. It creates unique post such are car listing etc based on the external DB. I also allows you to style and format your post.
https://wordpress.org/plugins/wp-all-import/

Pull content from a remote WordPress install

I need to create a wp widget that automatically pulls data from another wordpress install on a remote server.
Basically, the source site is a review site where offers vary over time. My widget will pull certain offers and make sure they stay updated.
Reviews on the source site are custom post types with custom meta fields that need to be fetched (price, offer, etc).
Looking around I've seen different suggestions: query the remote db, fetch the feed (does it store custom meta fields?), use json (which I barely know what is, but I am willing to learn new stuff).
What is the best method for my purpose and where can I find resources to help me achieving my goal?
Thanks for your help!
WordPress allows you to have an RSS feed per custom post type which is handy. Then you can make use of the WordPress Fetch Feed function to scoop what you need!
Are you the creator of the remote website?
You can create a new template in your theme
Code what you want to display in the format you want to display it
(json or just a bit of html)
In your wordpress admin create a new page and assign the new template
to it.
In your new site you just have to fetch the page

Defining dynamic pages in wordpress plugin

I am creating my first wordpress plugin. In it, the user will have the option to add new cities and view events on those cities.
My client requirement is that the URL must be like this
SITE_NAME/cities/NY
or
SITE_NAME/cities/Califonia
What is decided is that i will create a folder cities and If user tries to create a new city i will create a file in that folder with that city, Further more I will add the entry into the database as well.I will insert PHP code into the file as well.
Being new to WP plugins. Is my approach right (for creating files)? Is there any other way?
Your approach would work if you WEREN'T using Wordpress, but I would absolutely not advise doing what you're suggesting within the Wordpress Framework.
Rather than trying to reinvent the wheel, just about everything you want can be achieved with existing Plugins. I would absolutely suggest taking this route, especially if you don't have much experience with programming Wordpress Plugins.
Step 1:Install Wordpress
Self-explanatory. Can't do anything without this.
Step 2:Install Types
Installing the Types Plugin will give you a nice interface for registering your own Custom Post Types and many other features for extending Wordpress' core capabilities.
Step 3:Register your Custom Post Type
This is where things start to get complicated. Using Types, Register a Custom Post Type called Event. The reason why you want to have each event as its own Post is because each Event is unique. Cities are meant to encapsulate and define groups of events, which brings us to our next step:
Step 4:Register your Custom Taxonomy
Think of a Taxonomy as a way to classify things. Wordpress comes with two default Taxonomies: Categories (hierarchical) and Tags (non-hierarchical). In your case, you will want to define for your new Event Post Type a non-hierarchical Taxonomy called "Cities".
Step 5:Register your Custom Fields
Custom Fields are the easy part. What defines your event? Maybe some fields that define the start and end times of that particular event? A checkbox denoting free refreshments? The sky's the limit. What defining characteristics would all Events have that makes it an Event? Add those in the form of Custom Fields. These will show up on your Event Editor in the form of Meta Boxes. If you don't see the Meta Boxes on the Edit Page for a particular event, be sure to enable it by clicking Screen Options in the upper-right-hand corner of your screen and ticking the checkbox where your fields would be located.
Step 6:Configure your Permalinks
Much of this can be done either through Types itself (when configuring your Custom Taxonomy), or through .htaccess rewrites, or perhaps even through the Wordpress Permalinks Settings (though, it's fairly limited). My suggestion is to tweak your Custom Taxonomy and Permalink Settings first before messing with .htaccess.
And that's it! Hopefully this should be enough to get you started on everything you need.
maiorano84 wrote a fairly comprehensive guide to setting up the stuff you need, Rather than relying on plugins though, I prefer to show you how to write a plugin to register the custom post type and taxonomy. To that effect, I wrote a little plugin that should do everything you need and it has plenty of comments and links to the docs so that you can understand the Why of things.
Code
https://github.com/fyaconiello/WP_Cities_Events
This plugin does several things
Creates a custom post type Event
Creates a custom taxonomy City
Adds custom metaboxes to Event
Adds City taxonomy to Event
This plugin does not require any additional plugins to be installed, it is dependency free and only uses WP core.
URLS
As far as getting the correct URL Structure, I would suggest you read this thoroughly: http://codex.wordpress.org/Using_Permalinks.
I do not understand the structure you want
CITY is a single term w/i the taxonomy *cities*
EVENT is the post single
SITE_URL/cities/CITY would yield a page of all EVENT posts in that CITY
you need a url like: SITE_URL/cities/CITY/EVENT to read a specific event in a specific city
EDIT on how to urls:
In your Settings -> Permalinks administration panel select: "Post name" and save.
Then, go to your Ce Events -> Cities admin screen.
hover over one of your terms (in my case new york city) and click view.
it should open up that term(city)'s list view and the url structure looks like so: http://wp.local/city/new-york-city/
if you need city to read cities, modify line 102 of the main plugin file i shared with you:
'rewrite' => array('slug' => 'city'),
EDIT 2
Why not create City as a Custom Post Type? You can then define a slug 'cities' and get that result, and also add taxonomies like categories and tags to further aid navigation.
Don't do that. WordPress gives you a goog API for doing what you want to do: managing pretty URLs (slugs), database operations (you don't need to write/read files for that) and the right code workflow for registering and triggering actions.
So, I think you have to start reading the basics about WordPress plugins (its philosophy and API) and then just decide if you want to use its custom post types (ready to use) or if you want to create a specific content type.
yes this is fine approach.One more thing that you can do is that instead of adding the code inside the fie..Pick the code from DB.
Make a table in DB,create a column with varchar as datatype and insert the common code in it .

Categories