Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Custom Category Page with Genesis: Conditional tags WordPress

  • REFUNDED

I’ve spent a good quality of time trying to find a answer for this and I’m sure if I kept putting more time into it, I could manage to figure it out but I’d love a little help.

I decided I needed a custom category page for my clients website. Currently it is set up where they want the following:
domain/Category1/Category1.2/Post

Category1: Must list out all categories such as Category1.1, Category1.2 etc

Category1.1 (and so on): Must list out all posts that are in the 1.1 category
Also, category1.1 needs to only display the titles of the posts.

Each category needs a excerpt above the posts/category links in order to post a description about the categories/posts that are linked.

Basically, I need a custom category.php written with conditional tags based on what category page you're on.

I've come down to two codes needed for this custom category page..

<strong>Parent Category</strong>
<?php

remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'sk_show_subcategories_do_loop' );
/**
* Displays a list of linked child categories on category pages
*/
function sk_show_subcategories_do_loop() {

$cat = get_query_var('cat');
$category = get_category ($cat);

if ($category->cat_ID) {
$children = wp_list_categories("orderby=id&depth=0&hide_empty=0&title_li=&child_of=".$category->cat_ID."&echo=0");
// change depth to 1 if only the top level sub categories should be shown i.e., with children NOT expanded
if ($children) {
echo $children;
}
}

}

genesis();


<strong>Subcategories page:</strong>
add_action( 'pre_get_posts', 'sk_show_titles_only_category_pages' );
/**
* Show Linked Titles Only for Posts in Category Pages
*/
function sk_show_titles_only_category_pages( $query ) {

if( $query->is_main_query() && $query->is_category() ) {
$query->set( 'orderby', 'title' );
$query->set( 'order', 'ASC' );
// $query->set( 'posts_per_page', '2' );

//* Remove the post info
remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );

//* Remove the post thumbnail
remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );

//* Remove the post content
remove_action( 'genesis_entry_content', 'genesis_do_post_content' );
remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 );
remove_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 );

//* Remove the post meta
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );
remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );
remove_action( 'genesis_entry_footer', 'genesis_post_meta' );

remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'sk_custom_loop' );
}

}

function sk_custom_loop() {

//* Use old loop hook structure if not supporting HTML5
if ( ! genesis_html5() ) {
genesis_legacy_loop();
return;
}

if ( have_posts() ) : while ( have_posts() ) : the_post();

do_action( 'genesis_before_entry' );

printf( '<article %s>', genesis_attr( 'entry' ) );

do_action( 'genesis_entry_header' );

do_action( 'genesis_before_entry_content' );
// printf( '<div %s>', genesis_attr( 'entry-content' ) );
do_action( 'genesis_entry_content' );
// echo '</div>'; //* end .entry-content
do_action( 'genesis_after_entry_content' );

do_action( 'genesis_entry_footer' );

echo '</article>';

do_action( 'genesis_after_entry' );

endwhile; //* end of one post
do_action( 'genesis_after_endwhile' );

else : //* if no posts exist
do_action( 'genesis_loop_else' );
endif; //* end loop

}

Answers (1)

2014-04-19

Arnav Joy answers:

try this

<?php



remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_show_subcategories_do_loop' );

/**

* Displays a list of linked child categories on category pages

*/

function sk_show_subcategories_do_loop() {



$cat = get_query_var('cat');

$category = get_category ($cat);



if ($category->cat_ID) {

$children = wp_list_categories("orderby=id&depth=0&hide_empty=0&title_li=&child_of=".$category->cat_ID."&echo=0");

// change depth to 1 if only the top level sub categories should be shown i.e., with children NOT expanded

if ($children) {

echo $children;

}

else {
add_action( 'pre_get_posts', 'sk_show_titles_only_category_pages' );
}

}



}




/**

* Show Linked Titles Only for Posts in Category Pages

*/

function sk_show_titles_only_category_pages( $query ) {



if( $query->is_main_query() && $query->is_category() ) {

$query->set( 'orderby', 'title' );

$query->set( 'order', 'ASC' );

// $query->set( 'posts_per_page', '2' );



//* Remove the post info

remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );



//* Remove the post thumbnail

remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );



//* Remove the post content

remove_action( 'genesis_entry_content', 'genesis_do_post_content' );

remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 );

remove_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 );



//* Remove the post meta

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );

remove_action( 'genesis_entry_footer', 'genesis_post_meta' );



remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_custom_loop' );

}



}



function sk_custom_loop() {



//* Use old loop hook structure if not supporting HTML5

if ( ! genesis_html5() ) {

genesis_legacy_loop();

return;

}



if ( have_posts() ) : while ( have_posts() ) : the_post();



do_action( 'genesis_before_entry' );



printf( '<article %s>', genesis_attr( 'entry' ) );



do_action( 'genesis_entry_header' );



do_action( 'genesis_before_entry_content' );

// printf( '<div %s>', genesis_attr( 'entry-content' ) );

do_action( 'genesis_entry_content' );

// echo '</div>'; //* end .entry-content

do_action( 'genesis_after_entry_content' );



do_action( 'genesis_entry_footer' );



echo '</article>';



do_action( 'genesis_after_entry' );



endwhile; //* end of one post

do_action( 'genesis_after_endwhile' );



else : //* if no posts exist

do_action( 'genesis_loop_else' );

endif; //* end loop



}



genesis();


Beneath comments:

Parent category loads correctly with subcategory.

Sub-category fails to load the posts though that are in the subcategory.


Arnav Joy comments:

try this one

<?php



remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_show_subcategories_do_loop' );

/**

* Displays a list of linked child categories on category pages

*/

function sk_show_subcategories_do_loop() {



$cat = get_query_var('cat');

$category = get_category ($cat);



if ($category->cat_ID) {

$children = wp_list_categories("orderby=id&depth=0&hide_empty=0&title_li=&child_of=".$category->cat_ID."&echo=0");

// change depth to 1 if only the top level sub categories should be shown i.e., with children NOT expanded

if ($children) {

echo $children;

}

else {
add_action( 'pre_get_posts', 'sk_show_titles_only_category_pages' );
}

}



}




/**

* Show Linked Titles Only for Posts in Category Pages

*/

function sk_show_titles_only_category_pages( $query ) {



if( $query->is_main_query() && $query->is_category() ) {

$query->set( 'orderby', 'title' );

$query->set( 'order', 'ASC' );

$query->set( 'cat', get_query_var('cat') );



//* Remove the post info

remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );



//* Remove the post thumbnail

remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );



//* Remove the post content

remove_action( 'genesis_entry_content', 'genesis_do_post_content' );

remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 );

remove_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 );



//* Remove the post meta

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );

remove_action( 'genesis_entry_footer', 'genesis_post_meta' );



remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_custom_loop' );

}



}



function sk_custom_loop() {



//* Use old loop hook structure if not supporting HTML5

if ( ! genesis_html5() ) {

genesis_legacy_loop();

return;

}



if ( have_posts() ) : while ( have_posts() ) : the_post();



do_action( 'genesis_before_entry' );



printf( '<article %s>', genesis_attr( 'entry' ) );



do_action( 'genesis_entry_header' );



do_action( 'genesis_before_entry_content' );

// printf( '<div %s>', genesis_attr( 'entry-content' ) );

do_action( 'genesis_entry_content' );

// echo '</div>'; //* end .entry-content

do_action( 'genesis_after_entry_content' );



do_action( 'genesis_entry_footer' );



echo '</article>';



do_action( 'genesis_after_entry' );



endwhile; //* end of one post

do_action( 'genesis_after_endwhile' );



else : //* if no posts exist

do_action( 'genesis_loop_else' );

endif; //* end loop



}



genesis();


Beneath comments:

Same thing is happening..

Parent category is showing subcategories correctly.

Subcategory isn't showing posts in the particular subcategory.

I appreciate the help in trying to make this work!


Arnav Joy comments:

<?php



remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_show_subcategories_do_loop' );

/**

* Displays a list of linked child categories on category pages

*/

function sk_show_subcategories_do_loop() {



$cat = get_query_var('cat');

$category = get_category ($cat);



if ($category->cat_ID) {

$children = wp_list_categories("orderby=id&depth=0&hide_empty=0&title_li=&child_of=".$category->cat_ID."&echo=0");

// change depth to 1 if only the top level sub categories should be shown i.e., with children NOT expanded

if ($children) {

echo $children;

}

else {
add_action( 'pre_get_posts', 'sk_show_titles_only_category_pages' );
}

}



}




/**

* Show Linked Titles Only for Posts in Category Pages

*/

function sk_show_titles_only_category_pages( $query ) {



if( $query->is_main_query() && $query->is_category() ) {

$query->set( 'orderby', 'title' );

$query->set( 'order', 'ASC' );

$query->set( 'cat', get_query_var('cat') );



//* Remove the post info

remove_action( 'genesis_entry_header', 'genesis_post_info', 12 );



//* Remove the post thumbnail

remove_action( 'genesis_entry_content', 'genesis_do_post_image', 8 );



//* Remove the post content

remove_action( 'genesis_entry_content', 'genesis_do_post_content' );

remove_action( 'genesis_entry_content', 'genesis_do_post_content_nav', 12 );

remove_action( 'genesis_entry_content', 'genesis_do_post_permalink', 14 );



//* Remove the post meta

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_open', 5 );

remove_action( 'genesis_entry_footer', 'genesis_entry_footer_markup_close', 15 );

remove_action( 'genesis_entry_footer', 'genesis_post_meta' );



remove_action( 'genesis_loop', 'genesis_do_loop' );

add_action( 'genesis_loop', 'sk_custom_loop' );

}



}



function sk_custom_loop() {



//* Use old loop hook structure if not supporting HTML5

if ( ! genesis_html5() ) {

genesis_legacy_loop();

return;

}


query_posts('cat='.get_query_var('cat'));
if ( have_posts() ) : while ( have_posts() ) : the_post();



do_action( 'genesis_before_entry' );



printf( '<article %s>', genesis_attr( 'entry' ) );



do_action( 'genesis_entry_header' );



do_action( 'genesis_before_entry_content' );

// printf( '<div %s>', genesis_attr( 'entry-content' ) );

do_action( 'genesis_entry_content' );

// echo '</div>'; //* end .entry-content

do_action( 'genesis_after_entry_content' );



do_action( 'genesis_entry_footer' );



echo '</article>';



do_action( 'genesis_after_entry' );



endwhile; //* end of one post

do_action( 'genesis_after_endwhile' );



else : //* if no posts exist

do_action( 'genesis_loop_else' );

endif; //* end loop



}



genesis();


Beneath comments:

I tried it and the posts still aren't showing