asked on
<!-- Category back buttons -->
<? if ( is_tax( 'project-category', '5' ) ) { ?>
<!-- Retail -->
<div>
<a href="/category-retail/" title="view more retail projects">View More Retail Projects</a>
</div>
<? } ?>
<? if ( is_tax ( 'project-category', '20' ) ) { ?>
<!-- Education -->
<div>
<a href="/category-education/" title="view more retail projects">View More Education Projects</a>
</div>
<? } ?>
<!-- End Category back buttons -->
ASKER
<!-- Category back buttons -->
<?php if ( is_tax( 'project-category', 'retail' ) ) { ?>
<!-- Retail -->
<div>
<a href="/category-retail/" title="view more retail projects">View More Retail Projects</a>
</div>
<?php } ?>
<?php if ( is_tax ( 'project-category', 'education' ) ) { ?>
<!-- Education -->
<div>
<a href="/category-education/" title="view more retail projects">View More Education Projects</a>
</div>
<?php } ?>
<!-- End Category back buttons -->
Also tried doing it without the shorthand <? and changed it to <?php ?> - still no luck <? $image_gallery = get_post_meta($post->ID, "wpcf-additional-images");array_push($image_gallery, get_post_meta($post->ID, "wpcf-primary-image", true));
foreach ($image_gallery as $image) {
if ( count($image_gallery) == 2 ) { $layout = "layout2"; }
if ( count($image_gallery) == 3 ) { $layout = "layout3"; }
if ( count($image_gallery) == 4 ) { $layout = "layout3"; }
if ( count($image_gallery) > 4 ) { $layout = "layout3"; }
?>
<div class="portfolio-box <?=$layout;?>">
<a href="<?=$image;?>"><div class="bck-holder" style="background-image:url(<?=$image;?>)"></div></a>
</div>
<?
}
?>
Any idea on what I might be able to try next?
yeah I tried it that way as well but still nothing outputs and I would rather use the tax id incase the category name ever changesUse echo to output the result once the condition meet.
$taxonomy = get_query_var('taxonomy');
$queried_object = get_queried_object();
$term_id = (int)$queried_object->term_id;
here is an example of a loop that does work ... I'm thinking I may need to include $post->ID someplace perhaps?You can use $wp_query or get_queried_object_id().
global $wp_query;
$page_id = $wp_query->post->ID;
orget_queried_object_id()
ASKER
<!-- Category back buttons -->
<?php
$taxonomy = get_query_var('taxonomy');
$queried_object = get_queried_object();
$term_id = (int)$queried_object->term_id;
if ( is_tax( 'project-category', 'retail' ) ) { ?>
<!-- Retail -->
<div>
<a href="/category-retail/" title="view more retail projects">View More Retail Projects</a>
</div>
<?php } ?>
<?php
$taxonomy = get_query_var('taxonomy');
$queried_object = get_queried_object();
$term_id = (int)$queried_object->term_id;
if ( is_tax ( 'project-category', 'education' ) ) { ?>
<!-- Education -->
<div>
<a href="/category-education/" title="view more retail projects">View More Education Projects</a>
</div>
<?php } ?>
<!-- End Category back buttons -->
Could you please provide an example of how to implement the echo suggestion you gave?Check whether the requirement is meet and display the output.
if ( is_tax( 'project-category', 'retail' ) ) {
echo "TESTING";
}
ASKER
<?php
/**
* Template used for single posts and other post-types
* that don't have a specific template.
*
* @package Avada
* @subpackage Templates
*/
// Do not allow directly accessing this file.
if ( ! defined( 'ABSPATH' ) ) {
exit( 'Direct script access denied.' );
}
?>
<?php get_header(); ?>
<section id="content" <?php Avada()->layout->add_style( 'content_style' ); ?>>
<?php if ( fusion_get_option( 'blog_pn_nav' ) ) : ?>
<div class="single-navigation clearfix">
<?php previous_post_link( '%link', esc_attr__( 'Previous', 'Avada' ) ); ?>
<?php next_post_link( '%link', esc_attr__( 'Next', 'Avada' ) ); ?>
</div>
<?php endif; ?>
<?php while ( have_posts() ) : ?>
<?php the_post(); ?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'post' ); ?>>
<?php $full_image = ''; ?>
<?php if ( 'above' === Avada()->settings->get( 'blog_post_title' ) ) : ?>
<?php if ( 'below_title' === Avada()->settings->get( 'blog_post_meta_position' ) ) : ?>
<div class="fusion-post-title-meta-wrap">
<?php endif; ?>
<?php $title_size = ( false === avada_is_page_title_bar_enabled( $post->ID ) ? '1' : '2' ); ?>
<?php echo avada_render_post_title( $post->ID, false, '', $title_size ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
<?php if ( 'below_title' === Avada()->settings->get( 'blog_post_meta_position' ) ) : ?>
<?php echo avada_render_post_metadata( 'single' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
</div>
<?php endif; ?>
<?php elseif ( 'disabled' === Avada()->settings->get( 'blog_post_title' ) && Avada()->settings->get( 'disable_date_rich_snippet_pages' ) && Avada()->settings->get( 'disable_rich_snippet_title' ) ) : ?>
<span class="entry-title" style="display: none;"><?php the_title(); ?></span>
<?php endif; ?>
<?php avada_singular_featured_image(); ?>
<?php if ( 'below' === Avada()->settings->get( 'blog_post_title' ) ) : ?>
<?php if ( 'below_title' === Avada()->settings->get( 'blog_post_meta_position' ) ) : ?>
<div class="fusion-post-title-meta-wrap">
<?php endif; ?>
<?php $title_size = ( false === avada_is_page_title_bar_enabled( $post->ID ) ? '1' : '2' ); ?>
<?php echo avada_render_post_title( $post->ID, false, '', $title_size ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
<?php if ( 'below_title' === Avada()->settings->get( 'blog_post_meta_position' ) ) : ?>
<?php echo avada_render_post_metadata( 'single' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
</div>
<?php endif; ?>
<?php endif; ?>
<div class="post-content">
<?php the_content(); ?>
<h4>Testing normal content</h4>
<!-- Category back buttons -->
<?php
$taxonomy = get_query_var('taxonomy');
$queried_object = get_queried_object();
$term_id = (int)$queried_object->term_id;
if ( is_tax( 'project-category', 'retail' ) ) {
echo "TESTING";
}
?>
<?php
$taxonomy = get_query_var('taxonomy');
$queried_object = get_queried_object();
$term_id = (int)$queried_object->term_id;
if ( is_tax ( 'project-category', 'education' ) ) { ?>
<!-- Education -->
<div>
<a href="/category-education/" title="view more retail projects">View More Education Projects</a>
</div>
<?php } ?>
<!-- End Category back buttons -->
<?php
$theTerms = wp_get_post_terms( $post->ID, 'project-category', array("fields" => "all"));
$termLink = get_term_link($theTerms[0]->term_id, 'project-category');
?>
<? $image_gallery = get_post_meta($post->ID, "wpcf-additional-images");array_push($image_gallery, get_post_meta($post->ID, "wpcf-primary-image", true));
foreach ($image_gallery as $image) {
if ( count($image_gallery) == 2 ) { $layout = "layout2"; }
if ( count($image_gallery) == 3 ) { $layout = "layout3"; }
if ( count($image_gallery) == 4 ) { $layout = "layout3"; }
if ( count($image_gallery) > 4 ) { $layout = "layout3"; }
?>
<div class="portfolio-box <?=$layout;?>">
<a href="<?=$image;?>"><div class="bck-holder" style="background-image:url(<?=$image;?>)"></div></a>
</div>
<?
}
?>
<?php if ( ! post_password_required( $post->ID ) ) : ?>
<?php if ( '' === Avada()->settings->get( 'blog_post_meta_position' ) || 'below_article' === Avada()->settings->get( 'blog_post_meta_position' ) || 'disabled' === Avada()->settings->get( 'blog_post_title' ) ) : ?>
<?php echo avada_render_post_metadata( 'single' ); // phpcs:ignore WordPress.Security.EscapeOutput ?>
<?php endif; ?>
<?php do_action( 'avada_before_additional_post_content' ); ?>
<?php avada_render_social_sharing(); ?>
<?php $author_info = fusion_get_page_option( 'author_info', $post->ID ); ?>
<?php if ( ( Avada()->settings->get( 'author_info' ) && 'no' !== $author_info ) || ( ! Avada()->settings->get( 'author_info' ) && 'yes' === $author_info ) ) : ?>
<section class="about-author">
<?php ob_start(); ?>
<?php the_author_posts_link(); ?>
<?php /* translators: The link. */ ?>
<?php $title = sprintf( __( 'About the Author: %s', 'Avada' ), ob_get_clean() ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride ?>
<?php $title_size = ( false === avada_is_page_title_bar_enabled( $post->ID ) ? '2' : '3' ); ?>
<?php Avada()->template->title_template( $title, $title_size ); ?>
<div class="about-author-container">
<div class="avatar">
<?php echo get_avatar( get_the_author_meta( 'email' ), '72' ); ?>
</div>
<div class="description">
<?php the_author_meta( 'description' ); ?>
</div>
</div>
</section>
<?php endif; ?>
<?php avada_render_related_posts( get_post_type() ); // Render Related Posts. ?>
<?php $post_comments = fusion_get_page_option( 'blog_comments', $post->ID ); ?>
<?php if ( ( Avada()->settings->get( 'blog_comments' ) && 'no' !== $post_comments ) || ( ! Avada()->settings->get( 'blog_comments' ) && 'yes' === $post_comments ) ) : ?>
<?php comments_template(); ?>
<?php endif; ?>
<?php do_action( 'avada_after_additional_post_content' ); ?>
<?php endif; ?>
</article>
<?php endwhile; ?>
</section>
<?php do_action( 'avada_after_content' ); ?>
<?php get_footer(); ?>
$taxonomy = get_query_var('taxonomy');
echo "taxonomy :".$taxonomy
$queried_object = get_queried_object();
var_dump( get_queried_object() );
$term_id = (int)$queried_object->term_id;
echo "term_id :".$term_id
ASKER
<?php
$taxonomy = get_query_var('taxonomy');
echo "taxonomy :".$taxonomy ?>
here is a screen shot of what the above code looks like <?php
$queried_object = get_queried_object();
var_dump( get_queried_object() );
?>
This is what this looks like <?php
$term_id = (int)$queried_object->term_id;
echo "term_id :".$term_id
?>
this is what that looks like https://snipboard.io/lsHEad.jpgthis is a custom post type with slug "project" that has a custom taxonomy with slug "project-category" on my singles page within my custom taxonomy "retail" has a category id of 5 and "education" has a category id of 20.Noted. I didn't see the 5 or 20 for the taxonomy category based on the screened above. The current term_id is an empty value return.
<?php
$term_id = get_queried_object_id();
echo "term_id :".$term_id
?>
<?php
$tax = $wp_query->get_queried_object();
echo ''. $tax->name . '';
echo "<br>";
echo ''. $tax->description .'';
?>
<?php
$terms = wp_get_object_terms( get_queried_object_id(), 'project-category');
$term_id = $terms[0]->term_id;
echo "term_id :".$term_id;
?>
<?php
$terms = get_the_terms( $post->ID, 'project-category');
foreach ( $terms as $term )
{
$termID[] = $term->term_id;
}
echo "term_id :".$termID[0];
?>
<?php
global $post;
$terms = wp_get_post_terms( $post->ID, 'project-category',array('fields' => 'ids') );
print_r($terms);
?>
ASKER
<?php $term_id = get_queried_object_id(); echo "term_id :".$term_id ?>
https://snipboard.io/HQlwpG.jpg<?php $tax = $wp_query->get_queried_object(); echo ''. $tax->name . ''; echo "<br>"; echo ''. $tax->description .''; ?>
https://snipboard.io/EkR4ju.jpg<?php
$terms = wp_get_object_terms( get_queried_object_id(), 'project-category');
$term_id = $terms[0]->term_id;
echo "term_id :".$term_id;
?>
https://snipboard.io/flPs1S.jpg <?php $terms = get_the_terms( $post->ID, 'project-category'); foreach ( $terms as $term ) { $termID[] = $term->term_id; } echo "term_id :".$termID[0]; ?>
https://snipboard.io/SPfDuw.jpg <?php global $post; $terms = wp_get_post_terms( $post->ID, 'project-category',array('fields' => 'ids') ); print_r($terms); ?>
https://snipboard.io/r9UC6j.jpg ASKER
ASKER
<!-- Hospitality -->
<?php wp_reset_query(); ?>
<?php
$terms = get_the_terms( $post->ID, 'project-category');
foreach ( $terms as $term )
{
$term_id = (int)$term->term_id;
if($term_id==29){
echo " <div class='back-button-wrap'>
<a href='/category-hospitality/' title='view more hospitality projects'><button class='fusion-button button-flat fusion-button-default-size button-default button-1 fusion-button-default-span fusion-button-default-type'>View More Hospitality Projects</button></a>
</div>";
}
}
?>
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
Try using your custom taxonomy text instead
Example:
Open in new window
Open in new window