I was working on site pages here which comes in wedding category which comes in a custom taxonomy named listing.In my wedding category listing i dont want to display the price sticker but it shoud display in all other listing posts eg this page
I have tried
if ( in_category( 'wedding' )) {
?><style>.pricestricker{display:none!important;}</style><?php
}?>
also
if ( is_category( 'wedding' )) {
?><style>.pricestricker{display:none!important;}</style><?php
}?>
also
if ( has_term('listing', 'wedding' )) {
?><style>.pricestricker{display:none!important;}</style><?php
}?>
none of these worked.Please help.Thank You
Please try this once where the div "pricestricker" is present:
<div class="pricestricker" <?php if ( in_category( 'wedding' )) { echo 'style="display:none;"' }?>><span itemprop="price" class="wlt_shortcode_price">$0</span></div>
Here you should only write the php code inside the div "pricestricker" and remain will be default code.
or you can do:
<?php if ( !in_category( 'wedding' )) { ?>
<div class="pricestricker"><span itemprop="price" class="wlt_shortcode_price">$0</span></div> // This will be your default code
<?php } ?>
Related
Here is the my code, which is not working.
global $post;
echo get_the_title( wp_get_post_parent_id( $post->post->ID ) );
but this is not working.
thank you in advance.
For parent page id
$post->post_parent;
For current page title
$post->post_title;
For parent page id
<?php
echo wp_get_post_parent_id(get_the_ID());
?>
In Gutenberg:
wp.data.select('core/editor').getEditedPostAttribute('parent')
Hope will be helpful to someone
If you want i.e: create a link to the post parent:
<a href="<?= get_permalink($post->post_parent) ?>">
<?= get_the_title($post->post_parent) ?>
</a>
→ <?= the_title() ?>
which will result in i.e:
Latest News → Some news title
For Astra theme and for page template look.php I did this:
$post->post_parent; will nbot work cause in my case function is out of the loop. I run it via functions.php. $post->post_parent works perfectly when inserting it in page template, but not when editing theme function ;)
function add_script_before_header() {
$current = $post->ID;
$parent = $post->post_parent;
$grandparent_get = get_post($parent);
$grandparent = $grandparent_get->post_parent;
if ($root_parent = get_the_title($grandparent) !== $root_parent = get_the_title($current)) {
echo get_the_title($grandparent);
}
$after = $parent;
if ( is_page_template( 'look.php' ) ) {
echo $after . ' - ';
}
}
I have a WordPress site that has a ton of posts on it, all categorized. I set up a new theme, with pagination (15 posts per page), so the user can cycle through each page. Some of the categories paginate fine. Others are missing the final page.
So, if a category has 66 posts ... the first 4 pages show 15 different posts. However, when I click to view page 5, the page says "no posts found". Where did the last 6 posts go? They still show up in my administration (as published and visible). However, other category pages do not have this issue - for example, I have a category with 42 post, and it has 3 page ... the last page of which has 12 of the final post.
So, the pagination seems to be working fine (since it clearly shows the correct number of pages, for the number of posts). Please take a look below at the code I have... this is code from my templated index.php page (I didnt set up a category.php page, because it lists very similarly to the homepage).
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1; // Page
$args = "posts_per_page=15&paged=".$paged; // Base query
$category = get_queried_object(); // Get Cat info
$thisCat = $category->term_id; // Get Cat ID (if exists)
$tagID = get_queried_object()->term_id; // Get Tag ID (if exists)
echo '<!-- paged: '.$paged.'-->';
echo '<!-- catID: '.$thisCat.'-->';
echo '<!-- tagID: '.$tagID.'-->';
if (is_home() || is_front_page()) { // HOMEPAGE
query_posts($args.'&orderby=rand');
echo '<!-- args: '.$args.'&orderby=rand'.'-->';
} elseif ( is_search() ) { // SEARCH RESULTS ?>
<?php
$search_query = get_search_query();
query_posts($args.'&s='.$search_query);
echo "<!-- args: ".$args.'&s='.$search_query."-->"; ?>
<h1>Search</h1>
<div class="content_labels">
<div class="content_label">SEARCH RESULTS FOR: <?php echo $s; ?></div>
</div>
<div class="clear" style="margin:0 0 10px 0;"></div>
<div class="previouspage">
<< Previous Page
</div><?php
} elseif( is_category() ) { // CATEGORY
query_posts($args.'&cat='.$thisCat);
echo '<!-- args: '.$args.'&cat='.$thisCat.'-->'; ?>
<div class="content_labels">
<div class="content_label">Category:</div>
</div>
<h1><?php single_cat_title( '', true ); ?></h1>
<div class="clear" style="margin:0 0 10px 0;"></div>
<div class="previouspage">
<< Previous Page
</div><?php
} elseif( is_tag()) { // TAGS
echo '<!-- args: '.$args.'&tag_id='.$tagID.'-->';
query_posts($args.'&tag_id='.$tagID); ?>
<div class="content_labels">
<div class="content_label">Tag:</div>
</div>
<h1><?php single_tag_title(); ?> </h1>
<div class="clear" style="margin:0 0 10px 0;"></div>
<div class="previouspage">
Previous Page
</div><?php
}
if ( have_posts() ) :
$i=1;
while ( have_posts() ) : the_post(); ?>
// PAGE CODE GOES HERE
endwhile; ?>
<?php base_pagination(); // PAGINATION CODE ?>
<?php endif; ?>
Here is the pagination code, from my functions.php ... I don't think this is the issue...
function base_pagination() {
global $wp_query;
$big = 999999999; // This needs to be an unlikely integer
// For more options and info view the docs for paginate_links()
// http://codex.wordpress.org/Function_Reference/paginate_links
$paginate_links = paginate_links( array(
'base' => str_replace( $big, '%#%', get_pagenum_link($big) ),
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages,
'mid_size' => 5
) );
// Display the pagination if more than one page is found
if ( $paginate_links ) {
echo '<div class="pagination">';
echo $paginate_links;
echo '</div><!--// end .pagination -->';
}
}
Can anyone see what is going wrong? I've been playing with this for several hours, and I can't seem to find a solution...
So, I did some digging, and tried some things... I couldn't find anything wrong with the code above. The query was correct (showing 15 per page, for each category archive page, etc.), and the pagination was working ... In the end, the default POSTS PER PAGE was conflicting with my own posts_per_page=15 query. Not sure WHERE this conflict was occurring (that is beyond my skills) - but I did learn how to stop it.
Under SETTINGS - READING ...
I just changed the "Blog pages show at most" to "15"
This wasn't an ideal fix (since I don't know where this problem started, and I can't adjust custom "posts_per_page" if it differs from 15)... but my site now works how I want.
I ran into a little problem and I might need your help to sort it out.
I an building a website that uses custom taxonomies and tags posts accordingly. So, there is a page like http://example.com/custom-taxonomy/term that displays all the posts tagged with "term".
The visitor should be able to go to http://example.com/custom-taxonomy/ and see a lists of all the terms that are used inside that custom taxonomy in order to browse them. This list should also be "paginated" since some taxonomies could have quite a lot of terms in them.
Any ideas on how I should handle this?
Thanks a bunch!
I'll answer my own question here, maybe it will help others.
I have created a custom page template that uses get_terms to get the terms for a specific taxonomy and iterates through them displaying them in the desired manner.
I then created a page with the exact same slug as the main taxonomy slug (http://example.com/actors in this case) and thus when going to /actors/ you actually see the page created that acts as an index page for the taxonomy. You can see it in effect at http://couch.ro/actori/
In the actual code I am also using the Taxonomy Images plugin for having images on the actual tags so the get_terms is executed through the apply_filter() function. You have the full code for the template below. Any feedback is highly appreciated!
<?php
/*
Template Name: Taxonomy Index
*/
$slug_to_taxonomy=array('actori'=>'actor','regizori'=>'director');
$terms_per_page=get_option( 'c2c_custom_post_limits' );
if ($terms_per_page['archives_limit']==0)
{
$terms_per_page=get_options('posts_per_page');
}
else
{
$terms_per_page=$terms_per_page['archives_limit'];
}
$slug=$post->post_name;
if (!isset($slug_to_taxonomy[$slug]))
{
header("Location: /");exit;
}
else
{
$taxonomy=$slug_to_taxonomy[$slug];
}
$terms_page=get_query_var('paged');
if (empty($terms_page))
{
$terms_page=1;
}
$terms=apply_filters( 'taxonomy-images-get-terms', '',array('having_images'=>false,'taxonomy'=>$taxonomy, 'term_args'=>array('offset'=>($terms_page-1)*$terms_per_page,'number'=>$terms_per_page)) );
if (empty($terms))
{
header("Location: /");exit;
}
$processed_terms=array();
foreach ($terms as $term)
{
if (!empty($term->image_id))
{
$image_src=wp_get_attachment_image_src($term->image_id,'archive-thumbnail');
$image_src=$image_src[0];
}
else
{
$image_src='http://couch.ro/wp-content/uploads/couchie_75.png';
}
$term_posts=get_posts(array('posts_per_page'=>3,'tax_query'=>array(array('taxonomy'=>$taxonomy,'field'=>'slug','terms'=>$term->slug))));
$actual_term_posts=array();
foreach ($term_posts as $post)
{
$actual_term_posts[$post->post_title]=get_permalink($post->id);
}
$processed_terms[]=array(
'name'=>$term->name,
'description'=>$term->description,
'url'=>get_term_link($term),
'image'=>$image_src,
'posts'=>$actual_term_posts,
'count'=>$term->count
);
}
$has_next_page=(isset($processed_terms[$terms_page]));
get_header();
?>
<div class="posts-wrap">
<div class="archive-title_wrap"><h1 class="archive-title"><?php the_title(); ?></h1></div>
<div id="post_list_wrap">
<?php
foreach ($processed_terms as $term)
{
echo "<div class='post post-archive'>
<a href='{$term['url']}' title='{$term['name']}'><img src='{$term['image']}' alt='{$term['name']}'></a>
<div class='rating' style='text-align:right;'>{$term['count']} ".($term['count']==1?'review':'reviewuri')."</div>
<h2 class='index-entry-title'>
<a href='{$term['url']}' title='{$term['name']}'>{$term['name']}</a>
</h2>
<div class='archive-meta entry-meta-index'>
<span>";
$first_term_post=true;
foreach ($term['posts'] as $title=>$link)
{
echo ($first_term_post?'':', ')."<a href='{$link}' title='{$title}'>{$title}</a>";
$first_term_post=false;
}
echo "</span>
</div>
</div>";
}
?>
</div>
<?php if ($terms_page>1 OR $has_next_page) { ?>
<div class="navigation">
<div class="nav-prev left"><?php if ($terms_page>1) echo "<a href='/{$slug}/".($terms_page>2?"page/".($terms_page-1)."/":'')."'>".__('« Previous Page', 'designcrumbs')."</a>"; ?></div>
<div class="nav-next right"><?php if ($has_next_page) echo "<a href='/{$slug}/page/".($terms_page+1)."/'>".__('Next Page »', 'designcrumbs')."</a>" ?></div>
<div class="clear"></div>
</div>
<?php } ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
You can use query_posts function like this
$termname = get_query_var('pagename'); //custom-taxonomy term
query_posts(array(
'post_type' => POST_TYPE,
'showposts' => $limit,
'custom-taxonomy' => $termname // use $term1.','.$term2.','.$term3 to get multiple terms posts
));
see Documentation at Wordpress
To get all Terms under Custom Taxonomy try this you will have full control.
global $wpdb;
$taxonomy = CUSTOM_CAT_TYPE;
$table_prefix = $wpdb->prefix;
$wpcat_id = NULL;
//Fetch category or Term as said
$wpcategories = (array) $wpdb->get_results("
SELECT * FROM {$table_prefix}terms, {$table_prefix}term_taxonomy
WHERE {$table_prefix}terms.term_id = {$table_prefix}term_taxonomy.term_id
AND {$table_prefix}term_taxonomy.taxonomy ='" . $taxonomy . "' and {$table_prefix}term_taxonomy.parent=0 ORDER BY {$table_prefix}terms.name ASC");
$wpcategories = array_values($wpcategories);
foreach ($wpcategories as $wpcat) {
$termid = $wpcat->term_id;
$name = $wpcat->name;
$termprice = $wpcat->term_price;
$tparent = $wpcat->parent;
}
Custom Menu Links are not displaying in category page. When i checked the source, it shows me like this.
<div class="sidebar-widget">
<h1 class="widget-title">Popular Categories</h1>
<div class="menu-cus_menu-container">
<ul id="menu-cus_menu" class="menu"></ul>
</div>
</div>
The same function i called for my home page. But it is working fine. The following code is in sidebar.php
<?php
if ( is_active_sidebar( 'sidebar-hompage-widget-area' ) && is_home() ) {
dynamic_sidebar( 'sidebar-hompage-widget-area' );
}
if ( is_active_sidebar( 'sidebar-category-widget-area' ) && is_category() ) {
dynamic_sidebar( 'sidebar-category-widget-area' );
}
if ( is_active_sidebar( 'sidebar-left-widget-area' ) ) {
dynamic_sidebar( 'sidebar-left-widget-area' );
}
?>
Please help me to find out right solution or suggest me to find my mistake.
As far as i think you have a Category page not a category.php or archive.php file. is_category() function only works within category.php or archive.php file. Instead of using is_category try use is_page('category').
For more information on is_category() see http://codex.wordpress.org/Function_Reference/is_category.
Is there a way to hide the featured image from SOME posts?
My blog is cur-mudg-eon.com and if you look at the most recent post (on the homepage) titled "Confucius Says..." you'll see that I've used the featured image and it shows some excerpt text. When you click on the title or pic it takes you to the post which shows the cartoon I wish to display, and the featured image that I want to hide/remove.
I only want to do this on some posts, but I would like to be able to keep the featured image on the homepage.
Is this possible?
EDIT:
Pastebin File as requested.
Based on Chris Herberts answer where would I add his code to this code found in my single.php file:
<?php if(has_post_thumbnail()) {
echo '<figure class="featured-thumbnail"><span class="img-wrap">'; the_post_thumbnail(); echo '</span></figure>';
}
?>
<?php } else { ?>
<?php if(has_post_thumbnail()) {
echo '<figure class="featured-thumbnail large"><span class="img-wrap"><span class="f-thumb-wrap">'; the_post_thumbnail('post-thumbnail-xl'); echo '</span></span></figure>';
}
?>
<?php } ?>
Another way to do this that does not depend on them all being in the same category is to use a Custom Field.
You would set a custom field for the post for which you would hide the featured image - in the image below I'm using "hide_featured_image" and "yes", as the key and value, respectively.
Then you would check to see if the "hide_featured_image" field is set to "yes" when calling calling the function to show the featured image. Here's an example:
$shouldHideFeaturedImage = get_post_meta($post->ID, 'hide_featured_image', true);
if ( $shouldHideFeaturedImage != 'yes' ) {
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
}
If all those posts are in the same categories, you can do something like this.
On your theme files, under the file single.php there should be something similar to this:
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
change it to something like:
if ( !in_category( array( 'category1', 'category2', 'etc' ) )) {
if ( has_post_thumbnail() ) {
the_post_thumbnail('medium');
}
}