Advice on page/slug architecture - wordpress

I am looking for some sage advice on how to best create a page/slug structure for a WP site I am building. It is a portfolio site that will showcase creative work. I have currently created several custom post types for things such as the portfolio/work items and for their associated clients and have created relationships between those items using the Advanced Custom Fields Plugin. All of this works great. What I am struggling with is how to create the best URL structure.
I have the following pages already created and working well:
/work/ - index page that shows all work regardless of client
/clients/ - list of all clients
I need to create the following pages:
/clients/client/ - this page would show all work associated with a specific client. Here is where I am struggling. I need help understanding how to use the page template system to set the correct page slugs. Can I use page slugs as part of my WP query? Can I simply query based on the custom post type? What do I name the page template file for this to work?
Appreciate any advice and/or examples anyone can offer. Thank you.

WordPress offers an easy mechanism to handle pages and posts as well that are being created and rendered. It is us who has to take up the challenge to do those wonderful designs and tasks that we need. Moving on to the following topic of page and slug architecture we shall discuss in detail.
First let us look onto the following thing.
Creating Page Template for Custom Posts Type
Ex: If you are creating the post type called news the WordPress system will look for the following structures.
single-{post-type}.php
archive-{post-type}.php
single-{post_type}.php
If your custom post type were 'news', and/or query_var = "news", WordPress would look for single-news.php to display the single or permalink of the post.
archive-{post_type}.php
If your custom post type were 'news', and/or query_var = "news", WordPress would look for archive-news.php to display the archive of posts.
If these files are not available in your Theme's directory WordPress will look for archive.php and single.php, respectively. If even these files are not present it will default to index.php.
Template File will be like this.
<?php
$args = array( 'post_type' => 'news', 'posts_per_page' => 10,'post_status'=>'publish','orderby'=>'ID','order'=>'DESC' );
$the_query = new WP_Query( $args );
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
Hence from the above code you can display the Latest Posts from News category in the count of 10.
If you need the count to be infinite you have to change the post_per_page=10 to post_per_page=-1.
Hope so this reference and advice that i have tried to explain will be helpful for you. Still if you face any issues about my explanation comment over to my answer and i am there to help you.

I didn't go this exact route to resolve my question as I am using the Advanced Custom Relationships plug-in. My solution is somewhat similar to this: https://www.advancedcustomfields.com/resources/querying-relationship-fields/ - but your response was very helpful and got me going on the right track, thank you!

Related

WordPress custom taxonomy templates

I have a lot of different custom taxonomies and each one has specific template (taxonomy-customtax.php)
For now the templates are placed in the root of my theme.
Since we are able to place some template files in a subfolder (except for archive template), I would like to know if the following code is a correct way to do?
The code is in taxonomy.php in root of my theme:
<?php
$taxonomy = get_queried_object()->taxonomy;
if ($taxonomy == 'customtax')
{
get_template_part('template/customtax');
exit;
}
wp_safe_redirect(site_url('/'));
exit;
?>
Is there any problem if do that way?
Thank you
Basicaly that should work just fine. But as soon as you get my different post types or taxonomies, you would get a huge conditional script. Lets say, you have a archive page. You want to display the article teasers with different content and design for each post type or taxonomy. I would recommend you for example the following:
<?php get_template_part('templates/teaser', get_post_type()); ?>
<?php get_template_part('templates/content', get_post_type()); ?>
or for a taxonomy term (i.E. Category):
<?php $category = get_the_category(); get_template_part('templates/teaser', echo $category[0]->cat_name); ?>
<?php $category = get_the_category(); get_template_part('templates/content', echo $category[0]->cat_name); ?>
Note that this taxonomy solution only works for posts wich are assigned to a single taxonomy term. Hope you like the idea of handling it that way. I got wordpress sites up and running with 5-6 custom post types and 2-3 custom taxonomies and just one index.php as archive base.

Basic Fishpig Wordpress Integration - Display Custom Post on Homepage

I'm trying to create a slider on the homepage of my Magento site. I am totally new to Magento and have someone else on our team coding most of that stuff after realizing how far into the deep end I jumped.
My issue: I'm trying to pull custom posts from WP (with the paid advanced custom fields extension) to display an image that will go into a slider.
I'm stuck at the most basic part - pulling in a list of Wordpress posts.
I created a new file: mytemplatedirectory/default/template/home/slider.phtml with
<?php $posts = $this->getPosts() ?>
<?php foreach ($posts as $_post) : ?>
<?php echo $post->getPostContent() ?>
<?php endforeach ?>
and I put this into the CMS page in the Magento admin:
{{block type="core/template" template="home/slider.phtml"}}
But not even the default post is showing up.
If anyone has any guidance that would be extremely helpful. The beginning steps are what are throwing me off but it would also be nice to have help pulling the custom post and the advanced custom field (although it seems that Fishpig's documentation makes this pretty simple).
Thanks in advance! Sorry for such an amateur question.
The block type you're using does not include the getPosts() method, which is the reason your call to this returns nothing. If you change the block type to 'wordpress/sidebar_widget_posts' then the call to getPosts will return a post collection object.
The following link explains a little bit more about how to include this block and what you can do with it:
Display WordPress Blog Posts on the Magento homepage
Figured this out with Ben's help (who I believe is the creator of the excellent Fishpig extension).
I created a custom post (with the Custom Post Type UI plugin for WP) and a custom field (with the Advanced Custom Fields plugin for WP).
On my Homepage in the CMS I added in the content area
{{block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" post_count="5" post_type="slider_home" template="wordpress/sidebar/widget/slider_home.phtml"}}
In that block, slider_home is my post type and slider_home.phtml is a new file I created that pulls the code from wordpress/sidebar/widget/posts.phtml but customizes it to my need.
Within the loop in slider_home.phtml I took out what was currently there and added:
<?php $image = $post->getMetaValue('image'); ?>
<?php $url = $post->getMetaValue('url'); ?>
<a href="<?php echo $url; ?>" target="_blank">
<img src="<?php echo $image; ?>" />
</a>
which is pulling in the custom fields I made in Wordpress. works perfectly and now my client will be able to update their Magento site through the Wordpress CMS.

How Create Responsive One Page WordPress Theme with scrollable effects?

Where can I find a soucre that learn to create a Responsive One Page WordPress Theme so when I click on the menu item it scroll down.
Here is an example of what I want http://thememints.com/templates/?theme=Cingle%20WP.
I have had exactly the same question and after searching around found this post.
I was rather shocked to see the responses to this question. It seem to me like people are quick to answer questions without properly reading the question.
All the contributors have given solutions to responsive and parallax scrolling websites but not one has answered the real question.
It is not too broad, and it is not vague. All he is asking is how you go about creating a Single page theme in WORDPRESS.... no one gave any direction as to how to accomplish this.
Not sure why these answers got rated as usefull .
So after digging around with trial and error I found the following to answer the question as to how you go about to create a single page WORDPRESS theme.
One of the major aspect to understand is the Wordpress query-post function which allows you to post multiple page content such as home , about, service and content onto a single page.
To create the the menu structure to scroll to the different sections I found this tutorial to be usefull - create-a-single-page-wordpress-website
I hope this helps
As William Patton said this is a broad question but as far I can understand this may help :
http://www.designerledger.com/parallax-scrolling-tutorials/ for the one page theme.
and a basic start for wordpress development theme :
http://codex.wordpress.org/Theme_Development
Update : I found this awesome plugin that helps you create full screen pages
https://github.com/alvarotrigo/fullPage.js
EDIT 2016
Due to the many up votes at user3263807 answer I made a small/basic one page guide for wordpress. For css/js there are plenty good tutorials and plugins over the internet. Also I assume you are familiar with WordPress Themes.
First of all you should create a template file for your one page. Let's call it template-one-page.php. The template name, commented inside the file, is the name that will appear in Page Attributes -> Template when you creating a page inside admin panel. After that create a page, ie Home, and assign as template your template. If you want your page to appear as front page (when you enter mydomain.com this page will be shown) go to Setting->Reading->Front page displays->A static page and set as front page your page.
// File Security Check
defined('ABSPATH') OR exit;
/*
Template Name: One Page
*/
?>
Normally a one page has sections. So we want to decide what type of sections we want. It could be pages, child pages, posts, custom fields (like a repeater from ACF) etc.
<?php
$id = get_the_ID(); // The page id
$sections = get_posts(array('post_type' => 'page', 'post_parent' => $id)); // get all child pages
foreach ($sections as $key => $section):
?>
<section id="page-<?php $section->ID; ?>" <?php post_class('', $section->ID); ?>>
<h1><?php echo get_the_title($section->ID); ?></h1>
</section>
<?php endforeach; ?>
Or with a Loop
<?php
$id = get_the_ID(); // The page id
$query = new WP_Query( array('post_type' => 'page', 'post_parent' => $id) ); // get all child pages
if($query->have_posts()):
while ( $query->have_posts() ) : $query->the_post();
?>
<section id="page-<?php the_ID() ?>" <?php post_class(); ?>>
<h1><?php the_title(); ?></h1>
</section>
<?php endwhile; wp_reset_postdata(); ?>
<?php endif; ?>
You can query what ever you want depending the need of your site.
you should take look at below link:
[1] http://www.1stwebdesigner.com/css/responsive-website-tutorial/
[2] http://www.1stwebdesigner.com/css/create-a-responsive-website-video-tutorial/
[3] http://readwrite.com/2013/04/16/10-developer-tips-to-build-a-responsive-website-infographic#awesm=~okrhufNGLHp1mh (Best one to keep points in mind while creating )
Thanks.
Here is full detailed video tutorial that deals with setting a one-page scrolling Wordpress website from any theme you want. Need to join - there is a free trial. This allows you to "peek under the hood" and understand the principle of how the other one page themes and plugins were created.
http://www.lynda.com/WordPress-tutorials/WordPress-Building-One-Page-Style-Site/169876-2.html
I have looked into several ready-made themes, such as Onesie and OneEngine, and found them a nightmare to manage on the back end, very user unfriendly. The content of the long home page with several sections in both themes is managed not through the Pages section, like one would assume, but through a different admin section in the Appearance folder, with none of the usual Wordpress interface controls. The tutorial above deals with it properly, with the real Wordpress Pages assembled by a custom loop on the front page and menus working in the same way as built-in Wordpress menus.
I used localscroll and scrollTo jquery plugin in my one page theme, it's working fine.
The plugins link:http://flesler.blogspot.com
After you imported the jquery and plugins files into your page, just call the function like below, then if you click a anchor link, the page will scroll up or down smoothly.
$.localScroll({
target:'body',
duration:1000,
queue:true,
hash:true,
easing:'easeInOutExpo',
offset: {left: 0, top: -55}
});

Wordpress - Get name of Category a post belongs to?

in Wordpress on a post how can I get the name of the category it belongs to (each post will only have one category on my website).
The version of wordpresss you're using is very much relevant for your question, but a good place to start would be the wordpress codex where you can find for example the documentation of this function.
It is also important to know whether your code will be placed within the infamous loop (which would be the case if you're editing the post template) or not (for example, if your code goes at the sidebar, header, etc).
Assuming the first case, and taking the example from the manual, you could use:
<?php
$categories = get_the_category();
// there is only one, so extract the first from the array
$category = $category[0];
?>
These can go in header.php for generating meta tags, page titles, etc.
<?php echo trim(strip_tags(category_description())); ?>
<?php echo single_cat_title(''); ?>
Also see Template Tags/single cat title « WordPress Codex

custom wordpress page

I'd like to implement a custom post retrieval page in wordpress. Basically, I'm using AJAX to call this page that will be passed a post ID and retrieve certain data from that post.
Note: please don't mistake this as a template question. I do not want a template for one single page -- I am looking to make this page query multiple different posts based on postID and return certain data from that post.
So I tried creating a page
<?php
$args=array(
'p'=>'77'
);
$friends = new WP_Query($args);
?>
<?php if ($friends->have_posts()) : the_post(); ?>
<?php the_title(); ?>
<?php the_content(); ?>
<?php else: ?>
<p>Sorry, no posts are available.</p>
<?php endif; ?>
But this does not work since it is not loading in the wp functions to handle the query.
Thanks in advance for any help!
You have to include the wp-blog-header.php file. If the page you are creating is in your theme's folder then you would put something like this at the top of your code
<?php require_once ('../../../wp-blog-header.php');?>
I think I guess what you are trying to do, and it sounds like you are going about it the wrong way. Do not make a 'new page' in the admin interface. What you want to do is serve up a file (JSON, XHTML fragment, whatever) to your Javascript and include in it WP data, right? I know that problem, having used it in some of my plugins.
There are two techniques:
(1) This is what you need to do: make a new plugin (just a loose php file in wp-plugins with the same format header as the other plugins in there). Write your function along these lines:
function mydatapage(){
if (...$_SERVER['REQUEST_URI'] == the one I am using ...) {
$args=array(
'p'=>'77'
);
$friends = new WP_Query($args);
if ($friends->have_posts()) :
the_post();
the_title();
the_content();
else:>?
<p>Sorry, no posts are available.</p>
<?php endif;
die();
} //else do nothing and leave WP to serve the page normally
}
//Crucially:
add_action('init', 'mydatapage');
What that does is do a lookup when pages are loaded to see if the url matches the one you want to hijack and use to send your custom data. If it is, you send the data/file/whatever you feel like and exit (die).
Give a shout if you want more detailed syntax. It is a bit messy, but works well.
(2) Directly call your plugin file. WP will only handle files that do not already exist, and leave the rest to Apache. That means you can make a plugin file and call that directly using the .../wp-plugin/myfile.php url. You would need to include some of the WP core files to get things like WP_Query to work. It is marginally more fragile a method.

Resources