Articles of posts

Do not show children of a category

I’m trying the next code: $categoria = get_the_category(); $hijosCategoria = (array) get_term_children($categoria[0]->term_id, ‘category’); $queryBase = array(“cat”=>$categoria[0]->term_id,”category__not_in”=>$hijosCategoria); $objetoBase = new WP_Query($queryBase); if ($objetoBase->have_posts()){ while($objetoBase->have_posts()){ $objetoBase->the_post(); ?> <section class=”contenido”> <h2 class=”titulo-contenido”><?php the_title();?></h2> <article class=”texto-contenido”> <?php the_content();?> </article> </section> <?php } wp_reset_postdata(); } But I can always see the children of the post. I do not understand why […]

Sort Custom Post Type by Category ID then Post Name

I’m creating a custom post type archive page, and I have the posts sorted by category. However, I need the categories to be listed by ID, and the posts to be listed by name. Here is what I have so far: <?php //for a given post type, return all $post_type = ‘case-studies’; $tax = ‘portfolio’; […]

How to display two random-post sections that are each under their own category

<?php get_header(); ?> <div id=”containerHOME”> <div id=”left-div”> <!–Begin Sidebar–> <div id=”left-inside”> <?php if (get_option(‘earthlytouch_featured’) == ‘on’) get_template_part(‘includes/featured’); ?> <div class=”clear”>&nbsp;</div> <div class=”home-squares”> <div class=”home-headings”> <?php esc_html_e(‘Whats New?’,’EarthlyTouch’); ?> </div> <?php $args = array( ‘category_name’ => ‘whats’, ‘orderby’ => ‘DESC’, ‘ignore_sticky_posts’ => true, ‘posts_per_page’ => 3 ); $qry = new WP_Query($args); if ($qry->have_posts()) { while ($qry->have_posts() […]

Displaying Page Title on index.php

I have my posts page set as index.php, and on there I have my main heading (as I do on all pages). I’m having trouble displaying the page’s heading however. The page is called ‘Blog’ in WordPress, and has been specified as the posts page. If I output the page heading with wp_title(”);, I get […]

How to avoid duplicates when creating recent network posts

I’m using this code to get a list of custom posts (with custom fields) from the network for display in a php widget. It’s old, but it’s working fine: <?php switch_to_blog(4); ?> <?php $ca = new WP_Query(array(‘post_type’ => ‘conference_announcem’, ‘order’ => ‘DESC’, ‘posts_per_page’ => ‘-1’)); if ($ca->have_posts()): while( $ca->have_posts()): $ca->the_post(); ?> <p align=”left” class=”style2″> <a […]

How to add add more properties to WP_Post object in search results loop

I am using a plugin called Event Organiser, and it seems that it will only append its custom properties to the post object for all other instances of the WordPress loop except the search. Is there a way to access the search loop only and inject these properties into each WP_Post instance in the results?

How to add a class to edit_post_link?

My goal is obtain “Edit” button like this: <a class=”post-edit-link btn btn-default” href=”{$url}”>Edit this</a> The first attempt I was trying adopt was adding before and after params: edit_post_link( __(‘Edit this’), ‘<span class=”btn btn-default”>’, ‘</span>’); But the result wasn’t satisfying: <span class=”btn btn-default”> <a class=”post-edit-link” href=”{$url}”>Edit this</a> </span> First of all, it’s redundant: I must still […]

Display related post by tag name of current post

I am using thesis and i am trying to display the related post by there tag name. suppose i have post and that post have three tag or multiple tag like tag:- 1) car, 2)automobile, 3) mechanical so i want display the related post by the tag name of car,automobile,mechanical. I am trying the bellow […]

Format latest/newest post differently

I need to apply different formatting to only the latest/newest post. I need the first post to be full size image and full post, all subsequent posts must be excerpts with thumbnails. The code I am using only works on the first post per page so on the second page the first post is also […]

Every second post different class in blog view

To assign different classes to every 2nd post in blog view in WordPress adding this code into function.php was suggested as solution. Most people claim it is helpful, but to me it just adds odd at the end of the post class. There is no even class anywhere. function alternating_post_class($classes) { global $wp_query; $classes[] = […]