-
-
Save eri-trabiccolo/14ade3c986e9f3086843 to your computer and use it in GitHub Desktop.
<?php /*Add the following code at the very beginning of your template file, just after the Template declarative block */ ?> | |
<?php | |
// strangely you have to set this to false, typo in the core code. | |
// useful just when you display the page which uses this template in home as static page | |
// consider that the navigation will not work properly (and not because of customizr :P) | |
add_filter('tc_display_customizr_headings', '__return_false'); | |
add_filter('tc_post_list_controller', '__return_true'); | |
// use this to display the page title | |
add_action('__before_loop', 'print_page_title', 0); | |
function print_page_title(){ | |
?> | |
<header class="entry-header"> | |
<h1 class="entry-title "><?php echo get_the_title(); ?></h1> | |
<hr class="featurette-divider __before_content"> | |
</header> | |
<?php | |
} | |
?> | |
<?php /*Append the following code to your child-theme functions.php just if you want to display the page using the template as static page in home */ | |
/* as you can see here I've not used the php starting and closing tags since | |
your functions.php already starts with the first and doesn't have to be closed with the second!*/ ?> | |
// move list headings action | |
add_action('after_setup_theme', 'move_list_headings_action'); | |
function move_list_headings_action(){ | |
if ( class_exists('TC_headings') && method_exists('TC_headings', 'tc_set_post_page_heading_hooks') ){ | |
remove_action( 'wp' , array( TC_headings::$instance , 'tc_set_post_page_heading_hooks') ); | |
add_action( 'wp_head' , array( TC_headings::$instance , 'tc_set_post_page_heading_hooks') ); | |
} | |
} |
new version, add inline post list style
Cool,
is it going to be integrated in the core files this patch at some point? just to know if I have to keep-up with the code evolution here
Look that I made an error adding the inline style, now fixed.
For now just the filter part has been integrated. The other part (re-hooking) needs a further
investigation :D
Giorgio we're close to a solution for this in the core ;)
probably, keep finger crossed.
p.s.
thanks for that post about json-rest-api really interesting.. :D
Another mod version,
all the "issues" have been fixed in Customizr 3.3.12 and Customizr-Pro 1.0.16
Hey Rocco, I know this is not the place where to follow up / ask about custom loops (I will eventually post it on the forum when solved).
I have this problem, I don't seem to be able to filter a query for CPT with custom taxonomy; I have a CPT called 'publication' and a CT called 'publication-types'; under 'publication-types' I created some categories and one of those is called 'reports'.
I'm trying to filter in a custom loop 2 posts out of 'reports' only: http://www.firstcall.workingdesign.ca/publication-types/reports/ and in the future I will try to have 2 loops filtering also another category called 'letters', but for the sake of the question let's consider only 'reports'.
Here is the code I'm trying to put in my page template:
<!-- custom loop 1 -->
<?php
add_filter('tc_show_post_metas', '__return_true');
global $wp_query, $wp_the_query;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$wp_query = new WP_Query( array(
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
'post_type' => 'publication',
'publication-types' => $term->taxonomy,
'reports' => $term->slug,
'post_status' => 'publish',
'posts_per_page' => 2, //show n posts
//'cat' => 77, //include this category from the posts list
//'tag_id' => '77',
//'tag' => 'reports',
//'page_name' => 'publication-s',
//'taxonomy' => 'publication-types',
//'category_name' => 'reports',
//'page_name' => 'publication-types/reports',
//others parameters here: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
) );
?>
<!-- Customizr Loop here -->
<!-- reset the main query -->
<?php $wp_query = $wp_the_query; ?>
well, it does not work because I'm missing the point, it outputs only the 2 most recent posts under 'publication', what am I missing && || doing wrong?
https://github.com/giorgioriccardi/filtering-cpt-and-ct-in-WP-customizr-theme/blob/master/publications-page.php#L58
Hi Rocco,
I'll move the question to the forum, maybe somebody else has already a solution for this
Hey Rocco, problem solved:
https://github.com/giorgioriccardi/filtering-cpt-and-ct-in-WP-customizr-theme/blob/master/publications-page.php#L64
I was missing the part 'tax_query'... so many new things in WP all the time:
https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
this is a working custom loop that filters CPT, CT and related category:
<!-- custom loop 1 -->
<?php
add_filter('tc_show_post_metas', '__return_true'); //this applies only to Customizr theme
global $wp_query, $wp_the_query;
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$wp_query = new WP_Query( array(
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
'post_type' => 'publication',
'tax_query' => array( //https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters
array(
'taxonomy' => 'publication-types',
'field' => 'slug',
'terms' => 'reports',
)
),
'post_status' => 'publish',
'posts_per_page' => 2, //show n posts
//'cat' => 77, //include this category from the posts list
//others parameters here: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
) );
?>
Ciao
Hello Giorgio,
sorry for haven't replied, I don't get notified about new comments on gists.. do you know I could I? :D
p.s.
my last review of this:
~ line 36:
replace this:
self::$instance =& $this;
with this:
parent::$instance =& $this;
this to ensure you can still access TC_post_list::$instance, also with the modded class