Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #1250194

    Hi I created a custom post type by adding the code in the functions.php together with a custom taxonomy. The posts are called “Project” and the taxonomy “Typology”.
    I also use articles to appear as a list in the blog page (let’s call it “Gallery”).
    The projects are shown with the avia element “blog posts” in two different pages with different layouts (let’s call it “Page 1” and “Page 2”). I had to modify slightly some code of the file postslider.php, which I previously copied in my child theme, to show specific meta-data according to Page 1 and to Page2.
    I also created a copy of the archive.php into my child theme and named it archive-projects.php, as the custom taxonomies are linkable and one should be able to see an archive of the posts “projects” by taxonomy. The archive has a grid look as in Enfold the settings are for a grid layout.

    However I need that standard articles (the defaul ones) appear as a list on their archive page. But if I change form Enfold settings the blog layout, it affects also the custom archive-projects page. How can I deal with it? What should I modify to have a grid layout with my archive custom posts and a list layout in standard blog page?

    #1251150

    Hey Elena,

    Thank you for the inquiry.

    What did you change in the archive-projects.php file? Have you tried using the is_post_type_archive function to check if the current archive page shows the Project post type?

    // https://developer.wordpress.org/reference/functions/is_post_type_archive/

    We could also use the avf_blog_style filter to adjust the blog style of the Project archive page to blog-grid.

    Best regards,
    Ismael

    #1251152

    Hey Elena,

    Thank you for the inquiry.

    What did you change in the archive-projects.php file? Have you tried using the is_post_type_archive function to check if the current archive page shows the Project post type?

    // https://developer.wordpress.org/reference/functions/is_post_type_archive/

    We could also use the avf_blog_style filter to adjust the blog style of the Project archive page to blog-grid.

    Best regards,
    Ismael

    #1253253

    Hi Ismael, sorry for the late reply but I was ways the whole week.
    I did two attempts following your suggestions, but didn’t work. Here the code for each one.
    First of all I created a blog page where the standard post should be visible, and I set the child theme options for blog layout as a list (that’s how I want to see my standard post). Now the idea is that if I select a specific term taxonomy from the custom type posts (projects) I want them shown in a grid format.
    Here my two attempts to do it.

    ATTEMPT 1
    I used the is_post_type_archive function within the archive-project.php, simplifying it for my purposes:

     //above there's the code for handling the header, which I didn't change
    		<div class='container_wrap container_wrap_first main_color <?php avia_layout_class( 'main' ); ?>'>
    			<div class='container template-blog '>
    				<main class='content <?php avia_layout_class( 'content' ); ?> units' <?php avia_markup_helper(array('context' => 'content','post_type'=>'post'));?>>
    					<?php 
    						$tds =  term_description(); 
    						if($tds)
    						{
    							echo "<div class='category-term-description'>{$tds}</div>";
    						}
    					?>
                        <?php
                        if ( is_post_type_archive( 'projects' ) ) {
              				global $posts;
                            $post_ids = array();
                            foreach($posts as $post) $post_ids[] = $post->ID;
                            if(!empty($post_ids))
                            {
                                $atts   = array(
                                    'type' => 'grid',
                                    'items' => get_option('posts_per_page'),
                                    'columns' => 5,
                                    'class' => 'avia-builder-el-no-sibling',
                                    'paginate' => 'yes',
                                    'use_main_query_pagination' => 'yes',
                                    'custom_query' => array( 'post__in'=>$post_ids, 'post_type'=>get_post_types() )
                                );
    							/**
    							 * @since 4.5.5
    							 * @return array
    							 */
    							$atts = apply_filters( 'avf_post_slider_args', $atts, 'archive' );
                                $blog = new avia_post_slider( $atts );
                                $blog->query_entries();
                                echo "<div class='entry-content-wrapper'>".$blog->html()."</div>";
        					}
                       
                        ?>
    				<!--end content-->
    				</main>

    ATTEMPT 2
    I still have an archive-projects.php which is the exact copy of archive.php
    I added to my functions.php the following code:

    add_filter('avf_blog_style','avia_change_category_blog_layout_2', 10, 2); 
    function avia_change_category_blog_layout_2($layout, $context){
    if($context == 'archive-projects') $layout = 'blog-grid';
    return $layout;
    }

    In all 2 attempts, the blog layout (list) set in the child theme options overwrites the codes for the archive-projects.php. So if I click on a term taxonomy of the custom type posts, they appear as a list, like the blog page instead of appearing as a grid.
    Could you help me please?

    • This reply was modified 4 years, 1 month ago by elenapoliti.
    #1254247

    Hi,

    Thank you for the update.

    The $context value in the avf_blog_style filter is set to ‘archive’ by default on archive or category templates. Did you change it to “archive-projects”? Instead of checking for the value of the $context, try to use the is_post_type_archive function as suggested above.

    add_filter('avf_blog_style','avia_change_category_blog_layout_2', 10, 2); 
    function avia_change_category_blog_layout_2($layout, $context){
       if(is_post_type_archive("projects")) $layout = 'blog-grid';
       return $layout;
    }
    

    You may need to remove or temporarily disable the archive-projects.php file.

    Best regards,
    Ismael

    #1254280

    Hi Ismael, unfortunately your code didn’t work. I still see my projects listed as a list instead of a blog grid. It seems that notwithstanding the filter avf_blog_style, the settings in the theme options overwrite everything

    #1254804

    Hi,

    Did you disable or temporarily remove the archive-projects.php file? This might be necessary because the filter above changes the value of the $avia_config[‘blog_style’] in the template.

    Where can we see the projects archive page? Please post the login details (FTP and WP) in the private field so that we could check the page.

    Best regards,
    Ismael

    #1254882

    Yes I removed the archive-projects.php but nothing happened. Give me one hour to upload the web site to a temporary domain so that you can access. I will give you the access details and specify the pages. Thanks

    #1254893

    Ok in the private section I am going to add all the information you need to access my files

    • This reply was modified 4 years, 1 month ago by elenapoliti.
    #1255375

    Hi,

    Thank you for creating the staging site.

    In the functions.php file, we edited the avf_blog_style filter and replaced the is_post_type_archive function with is_tax to check if the page is the tipologie_progetti taxonomy archive page, or if it is showing posts from the said taxonomy. You may need to use additional is_tax function if you are planning to add more taxonomies in the future.

    Best regards,
    Ismael

    #1256002

    Thanks Ismael!! Sorry for the late reply. The problem is solved! I understand now where was the problem.
    you can close the ticket now.
    Great support as usual!

    #1256824

    Hi elenapoliti,

    Great :)

    We are closing the thread.

    If you need further assistance please let us know in a new one.

    Best regards,
    Victoria

Viewing 12 posts - 1 through 12 (of 12 total)
  • The topic ‘How to deal with custom post type and a relative custom archive page layout’ is closed to new replies.