Tagged: 

Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #1299276

    hello,

    I have made a custom post type called ‘advertisements’ and used the Blog Post element to display them on my home page. i am having 2 issues.

    1. It will only display three posts, i have made four posts and i have set it to display 15 per page with pagination enabled.

    2. How can i add more information to each post on the archive page? for example it is currently showing name, excerpt, date, and ‘read more’. I want add custom taxonomies or ACF fields so the user doesn’t have to click into it to see what it is.

    I have added login details below for your reference.

    thanks for your help.

    #1299871

    Hey w_archer,

    Thank you for the inquiry.

    We cannot find the page containing the “advertisements” post type, so we created a temp page, added the Blog Posts element and selected the Blade Length taxonomy. All of the items that belongs to the selected taxonomy or term display properly in the page. Where can we see the issue?

    To display the ACF fields, you will have to use get_field function and add it directly in the archive.php or in the include > loop-index.php file.

    // https://www.advancedcustomfields.com/resources/get_field/

    Best regards,
    Ismael

    #1300641

    Hi Ismael,

    I had a look at the page you made and compared it to the one i have. The difference is that you have chosen to display one of the taxonomies, which works normally. The problem occurs when i select category > uncategorised so that i can display all posts.

    i am trying to display all advertisements in one place so i can filter them using the taxonomies, but the way you have done will only show products of one taxonomy at a time.

    thanks

    #1300643

    Also, regarding my second question. I found that i can show the taxonomies using this code in the single.php template:

    <?php the_terms( $post->ID, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ ); ?>

    It seems to work on the past page but not on the home page or the test page you setup?

    #1300755

    Hi,

    The problem occurs when i select category > uncategorised so that i can display all posts.

    If you want to display all posts, then select all the available categories or taxonomies or do not select anything at all. It is possible that one of the item is not uncategorized.

    Would you mind providing a link to the page where you need to display this? Are you using the Grid Layout? If you are, then you will have to modify or add the code in the enfold/config-templatebuilder/avia-shortcodes/postslider/postslider.php file.

    Best regards,
    Ismael

    #1300862

    thanks i will look into the postslider.php file.

    I removed the avia block and started again. I managed to get everything showing, however now its showing pages to i.e. Contact Us, Privacy policy etc.

    I need to show my custom ‘advertisement’ post type only, and it isn’t one of the options. It is only displaying the taxonomies so i cant select all of them.

    So the way it is structured is:

    -Advertisement post type
    —taxonomy 1
    —taxonomy 2
    —taxonomy 3
    —taxonomy etc

    But the Blog post Element only has:
    —taxonomy 1
    —taxonomy 2
    —taxonomy 3
    —taxonomy etc

    If i select one of the taxonomies then its not showing all the posts, only the posts in that taxonomy.

    I have disabled post categories so there shouldn’t be an issue with one of the posts being uncategorised.

    #1301158

    Hi,

    If i select one of the taxonomies then its not showing all the posts, only the posts in that taxonomy.

    What if you select multiple taxonomies? Are the taxonomies unique for the custom post type advertisements, or are they shared by other post types? Unfortunately, you cannot select the post type directly, so a solution is to make sure that the selected taxonomies are unique to the desired post type.

    Best regards,
    Ismael

    #1301255

    hmm i think i will need to create a new taxonomy with only one option, assign it to all posts and hide it from the front end. Is it possible to make a taxonomy selected by default so all posts have it automatically?

    Also, i have tried editing postslider.php but i am having a really strange issue there. I have added the code below:
    <p><?php the_terms( $post->ID, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ ); ?></p>

    Which works as expected on single.php, but on the front end it is showing like this:
    <p>
    <!–?php the_terms( , ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ ); ?–>
    </p>

    As if the opening tag for the PHP is being interpreted as a HTML comment?

    #1301528

    Hi,

    it possible to make a taxonomy selected by default so all posts have it automatically?

    You might be referring to the taxonomy terms. This is possible by assigning a default term or category.

    // https://wordpress.com/support/posts/categories/#assigning-default-category

    And regarding the issue with the post slider, you might want to use the get_the_terms function instead so that you can properly create the layout or the markup.

    // https://developer.wordpress.org/reference/functions/get_the_terms/#user-contributed-notes

    Best regards,
    Ismael

    #1302107

    Hi Ismael, I have tried using all of the below without success:

    get_the_terms( $post->ID, ‘advertisements’ );
    get_the_terms( $post->ID, ‘brands’ );
    get_the_term_list( $post->ID, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ );
    get_the_term_list( get_the_ID(), ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ );
    the_terms( get_the_ID(), ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ );
    the_terms( $post->ID, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ );
    get_the_term_list( $the_id, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ );

    I think i was using the last one when I got the weird result i mentioned earlier.
    Not sure what i did wrong? I have added more code below to give some context for where i added it.

    $output .= ‘</header>’;
    if( ( $show_meta && ! empty( $excerpt ) ) || in_array( $show_meta_data, array( ‘always’, ‘on_empty_content’ ) ) )
    {
    $meta = “<div class=’slide-meta’>”;
    if ( $commentCount != ‘0’ || comments_open( $the_id ) && $entry->post_type != ‘portfolio’ )
    {
    $link_add = $commentCount === ‘0’ ? ‘#respond’ : ‘#comments’;
    $text_add = $commentCount === ‘1’ ? __( ‘Comment’, ‘avia_framework’ ) : __( ‘Comments’, ‘avia_framework’ );

    $meta .= “<div class=’slide-meta-comments’>{$commentCount} {$text_add}</div><div class=’slide-meta-del’>/</div>”;
    }
    $markup = avia_markup_helper( array( ‘context’ => ‘entry_time’, ‘echo’ => false, ‘id’ => $the_id, ‘custom_markup’ => $custom_markup ) );
    $meta .= “<time class=’slide-meta-time updated’ $markup>” . get_the_time( get_option( ‘date_format’ ), $the_id ) . ‘</time>’;
    $meta .= ‘</div>’;

    if( strpos( $blogstyle, ‘elegant-blog’ ) === false )
    {
    $output .= $meta;
    $meta = ”;
    }
    }
    $markup = avia_markup_helper( array( ‘context’ => ‘entry_content’, ‘echo’ => false, ‘id’ => $the_id, ‘custom_markup’ => $custom_markup ) );
    $excerpt = apply_filters( ‘avf_post_slider_entry_excerpt’, $excerpt, $prepare_excerpt, $permalink, $entry );
    $output .= ! empty( $excerpt ) ? “<div class=’slide-entry-excerpt entry-content’ {$markup}>

    <p>
    <?php the_terms( $post->ID, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ ); ?>
    </p>

    {$excerpt}</div>” : ”;
    $output .= ‘</div>’;
    $output .= ‘<footer class=”entry-footer”>’;

    #1302542

    Hi,

    What is the actual name or slug of the taxonomy that you created? Have you tried editing the includes > loop-index.php file instead of the single.php file?

    You can also use this hook in the functions.php file to render the terms below the post content.

     add_action("ava_after_content", function() {
    	if(!is_single()) return;
    
            // Make sure that the taxonomy name is correct
    	$terms = get_the_terms( get_the_ID(), 'brands' );
    
    	if ( $terms && ! is_wp_error( $terms ) ) {
    
    		$brands = array();
    
    		foreach ( $terms as $term ) {
    			$brands[] = $term->name;
    		}
    
    		$brands_list = join( ", ", $brands );
    
    		echo '<p class="av-post-brands">';
    			printf( esc_html__( 'Brands: <span>%s</span>', 'aviaframework' ), esc_html( $brands_list ) );
    		echo '';
    	}
     }, 999);
    

    Best regards,
    Ismael

    #1302730

    Hello,

    Couple problems. Firstly this is editing the blog page, i am trying to edit the archive page – postslider.php. The code you gave me above will add the brand taxonomy to the blog page but i have already done that with the single.php.

    Next problem is that the code above is displaying the Brand taxonomy as expected, but it looks like this:

    Brands: <span>Brand 2</span>

    Its adding the <span> tags as text not HTML

    This is similar to the problem i am having on postlisder.php, where the php is being rendered as text:
    <p>
    <!–?php the_terms( , ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ ); ?–>
    </p>

    the actual slug i am using are:
    ‘advertisements’ – post type
    ‘brands’ – taxonomy

    There are a whole lot of other taxonomies but if i can get one working then i can get the rest working.

    #1302731

    I think the problem is the syntax of the php. I don’t really know enough about php to be sure, but by the look of it i shouldn’t need to open the php tags before ‘the terms..’

    Since this whole thing is happening inside the $output variable.

    $output .= ! empty( $excerpt ) ? “<div class=’slide-entry-excerpt entry-content’ {$markup}>
    <p>terms should show here:<?php the_terms( $post->ID, ‘brands’, ‘Brand: ‘, ‘, ‘, ‘ ‘ ); ?></p>

    {$excerpt}</div>” : ”;
    $output .= ‘</div>’;

    #1303060

    Hi,

    What is the actual name or slug of the taxonomy that you created? We tried to login to the dashboard to check but the account above is no longer valid.

    e, i am trying to edit the archive page – postslider.php

    Try to extract the content of the above hook and place it in the archive.php or the postslider.php file. You may need to prepend or concatenate the terms to the $output as you have done above instead of using echo.

    
    // get the terms here
    
    $output .= '<div class="av-post-brands">';
    $output .= printf( esc_html__( 'Brands: <span>%s</span>', 'aviaframework' ), esc_html( $brands_list ) );
    $output .= '</div>'';
    

    Best regards,
    Ismael

    #1303482

    Hello,

    The slug is just brand-1, brand-2 brand-3 etc. I have added a new password for the login below. You can findall the taxonomies by visiting the Advertisements tab.

    I tried adding the above code to postslider.php but it gave me a syntax error: unexpected T_constant_Encapsed_string, i played around with the quotation marks but it was giving me wierd results on the front end. Not sure where i went wrong. I have added anther link below with a copy of the postlisder.php file and single.php file so give you a better picture of what i am working with.

    Hopefully that helps?

    #1303951

    Hi,

    We modified the postslider.php file and added the following code around line 896.

    if ( $terms && ! is_wp_error( $terms ) ) {
    
    						$brands = array();
    
    						foreach ( $terms as $term ) {
    							$brands[] = $term->name;
    						}
    
    						$brands_list = join( ", ", $brands );
    
    						$output .= '
    <div class="slide-entry-terms" class="av-post-brands">';
    						$output .= sprintf('Brands: <span>%s</span>', esc_html( $brands_list ));
    						$output .= '</div>
    ';
    					}
    

    You can check the result in one the brands’ archive pages. (see private field)

    Best regards,
    Ismael

    #1304311

    Hi Ismael,

    Something strange has happened. When i first visited your link it looked like it worked. I could see ‘Brand: Brand 1’. However after a refresh it disappeared? I can see the code you entered to the postlisder.php file is still there. Not sure why its not showing, i have cleared my browser cache.

    Also, It didn’t appear on the website home page where all the advertisements are displayed. Will this only work on individual taxonomy archive pages or should this work on the home page too?

    #1304318

    ok its working now, it must have been my browser acting up. However its still not showing on the home page?

    #1304323

    Hi,

    Thank you for the update.

    We edited the code again a bit, replaced the get_the_ID function with the actual ID of the entries or the posts in this line.

     // Make sure that the taxonomy name is correct
    $terms = get_the_terms( $the_id, 'brands' );
    

    The taxonomy terms are now displaying properly in the home page, and in the archive pages.

    Best regards,
    Ismael

    #1304358

    Your a legend! that works perfectly. This has been plaguing me for weeks.

    Now to add the other taxonomies i repeated the whole chunk of code above and replaced the taxonomy name. It works but there will about 8 taxonomies to display so that’s a lot of code, is there a way to condense it?

    #1305171

    Hi,

    You should be able to use the get_the_taxonomies function to get all taxonomies associated with a post.

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

    Try to replace the code with this one instead.

    $taxonomies  = get_object_taxonomies( get_post_type( $the_id ) );
                    $cats = '';
                    $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array('post_tag','post_format') );
    				$excluded_taxonomies = apply_filters( 'avf_exclude_taxonomies', $excluded_taxonomies, get_post_type( $the_id ), $the_id );
    
                    if( ! empty( $taxonomies ) )
                    {
                        foreach( $taxonomies as $taxonomy )
                        {
                            if( ! in_array( $taxonomy, $excluded_taxonomies ) )
                            {
                                $terms .= get_the_term_list( $the_id, $taxonomy, '', ', ', '' ) . ' ';
                            }
                        }
    
                        $output .= $terms;
                    }
    

    Best regards,
    Ismael

Viewing 21 posts - 1 through 21 (of 21 total)

You must be logged in to reply to this topic.