Site logo

Archived topic

Switch off masonry on specific taxonomies

32 replies · Started by Hans on August 12, 2018

Viewing posts 1–15 of 33

Hi everybody,

on specific taxonomy archives I use alphabetical order. I acchieved it by this code:

function member_abc( $query ) {
    if (($query->is_tax('ausschuss')) || ($query->is_tax('amtingemeinde')) ||($query->is_tax('ansprechpartnerin')) || ($query->is_tax('aufgabe')) || ($query->is_tax('funktionov')) || ($query->is_tax('mandat')) || ($query->is_tax('fraktionov'))) {
        $query->set( 'orderby', 'name' );
        $query->set( 'order', 'ASC' );
    }
}
add_action( 'pre_get_posts', 'member_abc' );

On exactly these archives I do not want to apply masonry as this destroys the abc-order from left to right. Which code will solve the problem?

I tried this code:

add_filter( 'generate_blog_masonry', 'tu_adjust_masonry' );
function tu_adjust_masonry( $masonry ) {
    if ((is_tax('ausschuss')) || (is_tax('amtingemeinde')) ||(is_tax('ansprechpartnerin')) || (is_tax('aufgabe')) || (is_tax('funktionov')) || (is_tax('mandat')) || (is_tax('fraktionov'))) {
        return 'false';
    }

    return $masonry;
}

It did not work.

Hi there,

Can you try this:

add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry ) {
    if ( is_tax( 'tax1', 'tax2')  ) {
        return 'false';
    }

    return $masonry;
}

Hi Leo,

it did not help!

Are those the taxonomies, or the terms?: https://codex.wordpress.org/Function_Reference/is_tax

Ideally, it would be like this:

add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry ) {
    $taxonomies = array(
        'some-taxonomy',
        'another-taxonomy',
        'one-more',
    );

    if ( is_tax( $taxonomies ) ) {
        return 'false';
    }

    return $masonry;
}

Hi Tom,

this did not chnge the situation. The taxnomy is part of a cpt. Might this be the source of trouble? I use the follwoing content-template:

<?php
/**
 * @package GeneratePress
 */
?>

<!-- Hans Keutgen Neue Datei für Theme - Mitglieder hehandeln -->

<style>
.post-image img {
	display: center;
    margin-left: auto;
    margin-right: auto;	
}
</style>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?> <?php generate_article_schema( 'CreativeWork' ); ?>>
	<div class="inside-article">
		<?php do_action( 'generate_before_content'); ?>
		<header class="entry-header">
			<?php do_action( 'generate_before_entry_title'); ?>
			<?php if ( generate_show_title() ) : ?>
				<?php the_title( '<h1 class="entry-title" itemprop="headline">', '</h1>' ); ?>
			<?php endif; ?>
			<?php do_action( 'generate_after_entry_title'); ?>
		</header><!-- .entry-header -->
		<?php do_action( 'generate_after_entry_header'); ?>
		<div class="entry-content" itemprop="text">
			<?php // the_content(); ?>
			<?php
			wp_link_pages( array(
				'before' => '<div class="page-links">' . __( 'Pages:', 'generatepress' ),
				'after'  => '</div>',
			) );
			?>
		</div><!-- .entry-content -->
		
		<?php do_action( 'generate_after_entry_content' ); ?>
		<?php do_action( 'generate_after_content' ); ?>
	</div><!-- .inside-article -->
</article><!-- #post-## -->

The code is in a child theme.

Any chance you can link me to one of those taxonomy archives?

I send the access data to your pre-sales support. The easiest way to see what happens: Look on menu bar "Ortsverein -> Who is who". This is an example of taxonomy 'fraktionov' and CPT 'mitglieder'.

Just as a test, does this work?:

add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
function tu_portfolio_masonry( $masonry ) {
    if ( is_archive() ) {
        return 'false';
    }

    return $masonry;
}

It will apply to all archives, so it's not the solution, but I just want to know if it works or not.

Hi Tom,

unforturnately it changed nothing - even archives stay in masonry.

That tells us something. Let's go back to our original function, and change it to this:

add_action( 'wp', function() {
    add_filter( 'generate_blog_masonry','tu_portfolio_masonry' );
} );

function tu_portfolio_masonry( $masonry ) {
    $taxonomies = array(
        'some-taxonomy',
        'another-taxonomy',
        'one-more',
    );

    if ( is_tax( $taxonomies ) ) {
        return 'false';
    }

    return $masonry;
}

Hi Tom,

things seem to become more complicated. Masonry is still there but additional problems have come up. Some taxonomies have no longer columns. I have to investigate this and will report tomorrow.

Sounds good - let me know what you find out.

Hi Tom,

I did not find a reason why there are three columns or one column in the taxonomies view in your last proposal. Prior to your last proposed code there where always three columns - all of them had the mansonry view.

When you enter the site - I send the access data to your pre-sales desk, you find the view as I designed it. Just go to "Examples" in the secondary menu under the primary one. There you find different views on taxonomies. When you enter Dashboard -> Snippets, the two deactivated snippets at the end of the list are your proposals. The penultimate snippet - your latest proposal - gives three/one column(s) back. The last one doesn't change anything - your first proposal.

I checked the taxonomy definitions - they are all exactly the same.

My wish is still to have these taxonomies in non-masonry view to get an alphabetical order despite of the size of the featured Image and lenghth of title.

Hi there,

So your "Who is Who" page is using this taxonomy: fraktionov

That was missing from the function. I added it to the code snippet, and masonry was disabled. Columns were also disabled though - do you want those back?

This archived topic is closed to new replies.