Common scenario in Wordpress: best practices - php

I'm facing a common scenario in the creation and the managing of a website that I'm still surprised I'm having difficulties in finding a good solution using Wordpress.
Let's say that I have a Wordpress website featuring food recipes. I have custom post types such as recipes and authors (of the recipes).
With the help of Advanced Custom Field plugin and Toolset plugin, it has been very easy to create the two custom post types and creating their custom fields together with the relationships between the objects.
Now, let's say that in multiple locations of the website I want to show a section called Spotlight Recipes where I show 3 featured recipes that I manually change every week.
What I would like to have in this situation, is a new item in the backend sidebar menu called Website Settings for example, that will allow me to manually choose the three recipes that will be featured in the section described above.
Let's say that I also want to display a section called Authors of the month and I always want to be able to manually choose the 5 authors that will be shown. It would be great if these could be also chosen inside the "Website Settings" backend page.
I think this is a very common scenario but I can't find a solution that I like. So I'm wondering: how websites using Wordpress solve this? Should I create a new custom post type called "MySettings" and create one instance of this, creating all its custom fields, and use it as a "singleton settings object"? It doesn't really appeal to me.

The best setup would be to add a new taxonomy for your Recipe custom post type. Then create a new category in that taxonomy named "Spotlight recipes".
You can add a custom taxonomy for users also.
There could be several scenarios for limiting the number of recipes shown. If you are declaring a recipe as recipe of the week as you add it then all you would need in your widget query is 3 parameters:
1) Set category to spotlight category of new taxonomy
2) Limit posts to 3 or 4
3) Sort by most recent
This way only the most recent recipes are shown at all times. It will also let you keep an archive of recipes of the week.

Related

Custom post types

I have created a custom post type and it is working fine. Is there a way that we can distribute a custom post type in two parts for example when we register the post type it usually show this in the dashboard. All Products, Add new, categories. These three options are shown and when we click on add new then we enter data.I want this that their should also be add new 2 in the same menu. Some fields are shown in the add new and some shown in the add new 2.
Is this scenario possible in word press. If yes then please help me out how can i do this. I have searched a lot but nothing found yet.
If I understand what you want correctly, then yes its possible.
You would need to have 2 custom post types and use metaboxes.
Here is handful generator tools:
Custom posts Generator - http://fooplugins.com/generators/wordpress-custom-post-types/
Metaboxes generator - http://jeremyhixon.com/tool/wordpress-meta-box-generator/
(in post types set "custom" instead of "post" and type your custom post name).
as for merging 2 custom posts types under one menu in admin - please read Group Custom Post Types in one menu Wordpress solution.

Navigating through custom post types in WordPress

I want to redesign my website using WordPress (as CMS) and Bootstrap (as front-end).
Now, I've been pretty successful at doing so, but I have one specific problem.
I have a tutorial website and I want the navigation structure to look like this :
If the user is on my 'website-name/tutorials' then display to him all of the tutorial series titles in an unordered list (so for example C++, XHTML and CSS - but not individual tutorials in each series)...
If the user clicks on some specific serie, then display an ordered list of the elements (so, if he clicks C++, then URL will be 'website-name/tutorials/cplusplus' and he will be able to see all of the tutorial in an ordered list).
If the clicks on one specific tutorial, then the URL goes (for example) 'website-name/tutorials/cplusplus/installing-the-program' and user gets all the content related to the tutorial.
Now, I have been experimenting with this and concluded that the best solution is to create custom post type named "Tutorial" and then make every single tutorial that post type.
However, since on 'website-name/tutorials/cplusplus' I want to display the list of tutorials in "C++" tutorial series and on 'website-name/tutorials' I want to display only the tutorial names, I don't know how to do that.
I tried to do that using Hiearchical posts (so, for example, I made a parent post named "C++" and it's children were all of the tutorials in the C++ serie).
However, I have a problem with that, because my C++ tutorial series has 100 tutorials, but it shows me 101 list elements (I made the website display all the custom post types in an ordered list), with the first one on the list being C++ (the parent post).
So, I'd like to echo the series name only on the 'website-name/tutorials' not on the beginning of the list.
I researched and people seem to use archive in custom post types, rather than parent/child system for this kind of navigation.
I just wanted some of the WP experienced users here to tell me, which is the better solution for my problem? Dealing with these parent/child problems or switching from parent/child posts to archive posts?
If I understand fully perhaps using standard posts and categories will do the trick? Your '/tutorials/' page can display the full list of all posts and when a user clicks on a specific category (e.g. C++) only the relevant posts will display.
You can use the following code to list posts of a specific category:
<?php query_posts( 'cat=20' ); ?>
Changing "20" with the chosen category ID.
Hope this helps!

Blog Post Associated with category

Hi I have been trying for a few hours now but I can't seem to figure it out for myself, I'm using the fish pig word-press plugin and I want to display word press blog post Associated with Magento category. There is a tab in the magento back end for doing so but I can't get it to display in the front-end
<action method="setEntity"><type><![CDATA[cms_page]]></type></action>
I think the key to getting it to display is the "set Entity" but I can't get it right.
I have tried to change it to many things but it still ain't working
If you're trying to display associated blog posts on the Magento category page, this isn't possible. At the time of writing, associating a blog post with a Magento category is just a quick way to associate that post with all of the products in the category.
I will be working on an update in the future that will allow you to show associations on the category page, but currently this would require some custom development on your part. To do this, you would need to query the database to extract the post/category relationships and then load a post collection based on that.

Wordpress custom post type or custom plugin for recipes?

I need to create a way for users to enter recipe information into a wordpress page that can be displayed globally, on their buddypress user page, import/export based on a defined xml standard and accept reviews for each recipe. In one example the user would be able to enter more than one type of ingredient (i.e. tomatoes) with each item having the same level of detailed fields yet when exported to xml, each tomato would have its own <tomato> tags. Hope that makes sense.
My question is should I build a custom plugin or can custom post types work? If a custom plugin would provide the best solution, can you suggest reading material that would put me on the best path to create such a solution?
In that case, custom post types would work just fine. The Types plugin can automate a good part of it, including the admin interface to edit your recipes.
You could define a new taxonomy for ingredients.

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