• Resolved Fra Calo

    (@frank-maio)


    I’m working on integrating the grid view on the post of my pageofpost template,

    so far I found an article on adding a class to output through fiunction.php ( https://www.transformationpowertools.com/wordpress/posts-in-two-columns-twenty-twelve ),
    but that also targets my page content…

    I’d like to integrate something to the function post_class filter in order to exclude the page-content..

    this is what I added to functions

    add_filter('post_class','category_three_column_classes');
    
    function category_three_column_classes( $classes ) {
    global $wp_query;
    if( is_page(xxxx) ) :
    $classes[] = 'three-column-post';
    if( $wp_query->current_post%3 == 0 ) $classes[] = 'column-post-left';
    endif;
    return $classes;
    }

    anybody have any ideas ?

Viewing 11 replies - 1 through 11 (of 11 total)
  • what is the full code of your page template?

    (please use the pastebin – https://codex.www.ads-software.com/Forum_Welcome#Posting_Code )

    Thread Starter Fra Calo

    (@frank-maio)

    Hi,

    here’s the link to my pageofpost template
    https://pastebin.com/S2qmJiFL

    I appreciate your help,

    possibly (untested) try to change the filter function to:

    add_filter('post_class','template_three_column_classes');
    
    function template_three_column_classes( $classes ) {
    global $list_of_posts;
    if( is_page_template('file-name-of-template.php') ) :
    $classes[] = 'three-column-post';
    if( $list_of_posts->current_post%3 == 0 ) $classes[] = 'column-post-left';
    endif;
    return $classes;
    }

    https://codex.www.ads-software.com/Conditional_Tags#Is_a_Page_Template

    Thread Starter Fra Calo

    (@frank-maio)

    thanks for the effort but it doesn’t work,
    it still targets the page content + posts —

    I have an idea:
    to bring in the posts of certain category i use the array

    $args = array(
    	'category_name' => 'portfolio',
    );

    you can see it in page template at line 38,

    do you think that integrating this in functions could be an optimal solution?

    Thread Starter Fra Calo

    (@frank-maio)

    I found the in_category tag that seems to work…
    any known contraindications?

    Thread Starter Fra Calo

    (@frank-maio)

    now I have a problem with the pagetemplate syntax,
    after the page content I have something that’s closing the #content and that’s messing up styles,

    do you see what it is?

    you actually don’t open the #content div (and #primary) in the page template;

    have a look and compare the template structure with the structure of page.php for instance; something like:

    get_header(); ?>
    
    		<div id="primary">
    			<div id="content" role="main">
    
    LOOPING HERE
    
    			</div><!-- #content -->
    		</div><!-- #primary -->
    
    <?php get_footer(); ?>
    Thread Starter Fra Calo

    (@frank-maio)

    Hi Alchymyth,
    it gets opened in header
    and with functions.php, depending on template, it gets targeted with different classes

    here is the function that targets the classes..

    function catchbox_body_classes( $classes ) {
    	$options = catchbox_get_theme_options();
    	$layout = $options['theme_layout'];
    	if ( function_exists( 'is_multi_author' ) && !is_multi_author() ) {
    		$classes[] = 'single-author';
    	}
    	if ( $layout == 'content-sidebar' && !is_page_template( 'page-disable-sidebar.php' ) && !is_page_template( 'page-fullwidth.php' )  && !is_page_template( 'page-onecolumn.php' ) && !is_page_template( 'page-of-post.php' ) ) {
    		$classes[] = 'content-sidebar';
    	}
    	elseif ( $layout == 'sidebar-content' && !is_page_template( 'page-disable-sidebar.php' ) && !is_page_template( 'page-fullwidth.php' )  && !is_page_template( 'page-onecolumn.php' ) && !is_page_template( 'page-of-post.php' ) ) {
    		$classes[] = 'sidebar-content';
    	}
    	elseif ( $layout == 'content-onecolumn' || is_page_template( 'page-onecolumn.php' ) && !is_page_template( 'page-disable-sidebar.php' ) && !is_page_template( 'page-fullwidth.php' ) && !is_page_template( 'page-of-post.php' ) ) {
    		$classes[] = 'content-onecolumn';
    	}
    	elseif ( is_page_template( 'page-disable-sidebar.php' ) || is_attachment() ) {
    		$classes[] = 'singular';
    	}
    	elseif ( is_page_template( 'page-fullwidth.php' ) || is_attachment() ) {
    		$classes[] = 'fullwidth';
    	}
    	elseif ( is_page_template( 'page-of-post.php' ) || is_attachment() ) {
    		$classes[] = 'fullwidth';
    	}
    	return $classes;
    }
    add_filter( 'body_class', 'catchbox_body_classes' );

    #content div closes in the page-template, (it does the same in the page.php) .

    as for my site I found a workaround working on .three-column-post css class,

    Thread Starter Fra Calo

    (@frank-maio)

    here’s the code i used in functions, with the tag in_category

    /*3 column-alchy-tweak */
    
    add_filter('post_class','template_three_column_classes');
    
    function template_three_column_classes( $classes ) {
    global $list_of_posts;
    if ( in_category( 'xxxxxxxxx' )) :
    $classes[] = 'three-column-post';
    if( $list_of_posts->current_post%3 == 0 ) $classes[] = 'column-post-left';
    endif;
    return $classes;
    }
    Thread Starter Fra Calo

    (@frank-maio)

    shoul I mark the thread Solved?

    Thread Starter Fra Calo

    (@frank-maio)

    topic closed

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘grid view on page-of-post.php’ is closed to new replies.