Data/Content Architecture in WordPress 3.1 - wordpress

Update
I solved it in that way:
What you need:
Custom Post Type
Enabled Plugin "Posts 2 Posts" (see comments below)
Enabled Plugin "Allow numeric stubs"
You'll need the Plugin "Posts 2 Posts" to assign posts tp pages. "Allow numeric stubs" is a plugin that will allow you to have numeric slugs for pages. If try to add pages named to 2011 or 2012 you'll get Page-Slugs like 2011-2 or 2012-2 because it is not possible to have a page slug that is a number.
First you have to add some Pages. For Example 2011, Nominees and Actors. Now you arrange the Pages as childs to your needs.
2011
-Nominees
--Actors
Your Url will now look like http://example.com/2011/nominees/actors
Now you have to add a Custom Post Type which contains your nominees. Add some nominees to your Post Type (should work with Articles too).
Register a connection type in your functions.php
function my_connection_types() {
// Make sure the Posts 2 Posts plugin is active.
if ( !function_exists( 'p2p_register_connection_type' ) )
return;
p2p_register_connection_type( array(
'id' => 'posts_pages',
'from' => 'page',
'to' => 'nominees' // Your Post-Type
) );
}
add_action( 'init', 'my_connection_types', 100 );
Now go to your Actor-Page, look for a MetaBox named "Connected Nominees" and add your nominees.
Edit your page.php
<article class="single entry">
<header class="post post-header">
<h1><?php the_title(); ?></h1>
</header>
<section class="post post-content">
<?php the_content(); ?>
<?php
// Find connected pages
$connected = p2p_type( 'posts_pages' )->get_connected( get_queried_object_id() );
// Display connected pages
if ( $connected->have_posts() ) :
?>
<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
<?php
// Prevent weirdness
wp_reset_postdata();
endif;
?>
</section>
</article>
Now you should be able to see you asigned Posts (nominees) on your Page Actors.
The solution is easy to understand for authors since they are working with default wordpress behaviors and the content connection process feels really native.
I'm looking for some data architecture best practices in WordPress 3.1.n
Here are the facts:
It is some kind of award
The Award has **n** different categories
People could be nominated
Each nominee could be asscociated with 1 category
Each category is grouped by year
Each category can contain up to 3 or 5 nominees
Categories/Terms(?)
2011
actor
special-effects
story
2012
actor
special-effects
story
For Example:
http://example.com/nominees/2011/actor/all-nominees-in-actor-cat-in-2011.html
http://example.com/nominees/2011/special-effects/all-nominees-in-special-effects-cat-in-2011.html
http://example.com/nominees/2012/special-effects/all-nominees-in-special-effects-cat-in-2012.html
Note: Custom Post-Types and Custom Taxonomies are fine but i can't get hirachical Taxonomy-Terms work.
Does anyone have some suggestions to solve this with WordPress?

You might consider creating an "Award" post type with categories being the types of awards... Best Actor, Special Effects, etc. Also you could tag each award post by what year it is. I like tagging the year vs a year as a category because it gives you the option to build and scale content by year as the site grows. However a category would work as well.
Then, perhaps create an Actor post type with each actors name, this would have the added benefit of being scaleable should you want to expand on actor profiles down the road. Then consider connecting them using something like the "Posts 2 Posts" plugin. Plugin here
This plugin is great for associating posts with other posts like a "review" post with a "product" post. You will essentially be doing the same thing except "review" would be substituted with "award" and "product" would be associated with "actor".

Related

template management with wordpress (underscore boilerplate)

I am using underscore to develop a wordpress theme.
I have a custom post type name project, thus I have, for instance, this url: http://a.site.local/projects/a-beauty/.
I have in my template-parts/ directory the file content-projects.
$ cat template-parts/content-projects.php
<h1>Project</h1>
When I browse http://a.site.local/projects/a-beauty/, I have my title but also the sidebar and the footer (even if they do not appear in my content-project.php nor in index.php).
Where are those widgets coming from / loaded ?
Add conditions to the header, footer and sidebar.
For whole custom post archive:
<?php if( !is_post_type_archive( 'project' ) ) : ?>
// wrap the code you don't want to show on that archive
<?php endif; ?>
For custom post only:
<?php if( !is_singular( 'project' ) ) : ?>
// wrap the code you don't want to show on the post
<?php endif; ?>
If you want to put the code you WANT to show, remove the '!' before condition.
P.S.
You can put the whole content in a condition, but keep the
</div><!-- #page -->
<?php wp_footer(); ?>
</body>
</html>
otherwise the page will break :)
Please share some more code from your project so we can easy to understand the real problem.

Display ACF fields on WooCommerce single product page via hook

This method works fine
Display ACF fields on WooCommerce single product page
but what if I want to use this code below. How do I have to format the code so that it works with the functions.php
$my_title = get_field('the_subtitle');
<?php if($my_title):?>
<span id="product-subtitle" class="product-subtitle subtitle"><?php echo $my_title;?></span>
<?php endif;?>

Is it possible to create a table in current database of wordpress using a static page only (not creating as plugin)?

I wrote my code as bellow,
<?php
/*
Template Name:Register Page
Template URI:
Author:yuva
Author URI:
Description:This Is Page for Gallery.
*/
get_header();
?>
<div class="regist">
<h2><?php the_title(); ?></h2>
<?php
global $wpdb;
$my_table=$wpdb->prefix.'your_users';
$sql="CREATE TABLE IF NOT EXISTS $my_table (id int(20) not null auto_increment,name varchar(40) not null,password varchar(20) notnull,PRIMARY KEY(id))";
include_once(ABSPATH.'wp-admin/includes/upgrade.php');
dbDelta($sql);
?>
</div>
<?php
get_footer();
?>
Can any one help me solve this?
Thank you!
Since this code has nothing to interact with the user how about writing the above code in your function.php instead of the template page??
And yes you can surely create tables if you want.
Yes it is possible, but don't forget to use CREATE TABLE IF NOT EXISTS .Otherwise your query create new table every time when page is executed and your previous data will be lost.

wordpress display pages

I use plugin wp-type
The wp-type plugin is used for making custom pages.
You can add for example a new field of type "file" and display the filelink in the page with the following code :
<?php
echo(types_render_field("file", array("title"=>"Download", "link"=>"true")));
?>
My problem is when I try to display files : in the main page everything's ok, but when I try to display the list of the posts with index.php it doesn't work.
This problem appears only with pages for posts I use :
<?php while (have_posts()) : the_post();
echo(types_render_field("file", array("title"=>"Download", "link"=>"true")));
endwhile;?>
and it works well.
Please help me to display all pages in index.php and each page file I try this :
<?php while (wp_list_pages( ));
echo(types_render_field("file", array("title"=>"Download", "link"=>"true")));
endwhile;?>
Replace your code to display page list:
while (wp_list_pages( )); to while (wp_list_pages( )):

Wordpress if else requirements for comments

I am not sure where to start, but I want to add in a symbol or change the css for the comments for registered users. Show a difference between non registered user comments and registered user comments.
How would I go about adding this to my wordpress website?
<div class="commentdetails">
<p class="commentauthor"><?php comment_author_link() ?></p>
<?php if ($comment->comment_approved == '0') : ?>
<em>Your review is pending approval by gsprating staff.</em>
<?php endif; ?>
<p class="commentdate"><?php comment_date('F jS, Y') ?>
IP/Hostname: <small>(coming soon)</small>
<?php edit_comment_link('Edit Comment','',''); ?>
</p>
I want to add make it so that the entire class is a different color if the user is a registered logged in user.
Here's an all php version of Saladin's code using the standard if/else sysntax:
<?php
if ($comment->user_ID) {
echo "<div class='comment_registeredUser'>";
}
else { // The user is not logged in
echo "<div class='commentdetails'>";
}
?>
Putting all the code in php has fixed execution errors for me. Of course, that may have been because I was doing something else wrong.
As comments are displayed in the wp_list_comments() function, you will need to edit the code there. The easiest way to achieve this is to use a simple if/else statement checking whether or not the comment has a user ID associated with it. If it does, that means the comment was made by a registered user.
Of course, as well as this, you will need to create a new CSS class to give the distinction. Here is some example code:
<?php if($comment->user_ID) : ?>
<div class="comment_registeredUser"> <!-- Or whatever you decide to call the CSS class -->
<?php else : ?> <!-- The commenter isn't a registered user -->
<div class="commentdetails">
<?php endif; ?>
// Then include the rest of the code as is
The $comment->user_ID variable will return a true if the comment poster is a registered user and was logged in when they posted the comment. The code above will assign your custom CSS class to the div if it does indeed return true. If not, it will simply apply the standard class and styling.
There is also a really good tutorial for developing themes over at the Wordpress Codex. Definitely worth having a read through if you are unsure on what you need to do to create/edit your WordPress theme.
Edit: Cleaned up the answer and better explained the correct logic.

Resources