You can use that code in any template you like – for example in sidebars or before/after main content. You just need to avoid using the shortcode in the main loop: everything else is up to you.
Let’s say you have a template like this:
<div id="content">
[your main loop]
</div>
<div id="sidebar">
[sidebar code]
</div>
You can use the shortcode above everything like that:
<?php do_shortcode('[showsingle ...]'); ?>
<div id="content">
[your main loop]
</div>
<div id="sidebar">
[sidebar code]
</div>
This will also work for the Category->Page binding, only if in the category.php files:
<?php do_shortcode('[showauto]'); ?>
<div id="content">
[your main loop]
</div>
<div id="sidebar">
[sidebar code]
</div>
Otherwise you can use it in your sidebar, maybe using the [showlist] shortcode:
<div id="content">
[your main loop]
</div>
<div id="sidebar">
<?php do_shortcode('[showlist ...]'); ?>
[sidebar code]
</div>
Hope it helps!
Thank’s. It works perfect when I associate a page to a category but not when I try to associate a specific post to a single category. The post is displayed in the whole pages, the homepage included. May be is the normal way to use your plugin ?
Anyway, is a good work π
We’re sorry but the exclusive link works only with pages, not posts.
Hi,
I struggle with this and searched through various forums but somehow I seem to be to stupid to get this up and running.
I’m using the Pinboard theme of one designs and I’m able to create a page that contains articles of a certain category by hardcoding the category id into on of the theme’s templates. This is how it looks:
<?php
/*
Template Name: #newsletter
*/
?><?php get_header(); ?>
<?php global $pinboard_page_template; ?>
<?php $pinboard_page_template = 'template-blog.php'; ?>
<?php if( pinboard_get_option( 'location' ) ) : ?>
<?php pinboard_current_location(); ?>
<?php endif; ?>
<div id="container">
<section id="content" class="column twothirdcol">
<?php $args = array( 'posts_per_page' => get_option( 'posts_per_page' ), 'paged' => max( 1, get_query_var( 'paged' ) ) ); ?>
<?php if( pinboard_get_option( 'blog_exclude_portfolio' ) ) : ?>
<?php $args['cat'] = '26'; ?>
<?php endif; ?>
<?php global $wp_query, $wp_the_query; ?>
<?php $wp_query = new WP_Query( $args ); ?>
<?php if( $wp_query->have_posts() ) : ?>
<div class="entries">
<?php while( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php get_template_part( 'content', get_post_format() ); ?>
<?php endwhile; ?>
</div><!-- .entries -->
<?php pinboard_posts_nav(); ?>
<?php else : ?>
<?php pinboard_404(); ?>
<?php endif; ?>
<?php wp_reset_postdata(); ?>
<?php $wp_query = $wp_the_query; ?>
</section><!-- #content -->
<?php get_sidebar(); ?>
<div class="clear"></div>
</div><!-- #container -->
<?php get_footer(); ?>
How do I now manage to use [showauto] with this template to be able to select different categories for different pages using this template?
Thans!
Hi aski71, [showauto] relies on the global $cat, so you have to overwrite it before calling the shortcode.
Waiting for WP 3.6 and our new page2cat release, you can find better documentation (with usage examples and screenshots) on:
http://dev.swergroup.com/pages-and-posts-shortcodes/wiki/Home