I’ve got an issue with getting posts from a specific category, without getting posts from its subcategory.
—
I’ve got a sidebar that only shows a post regarding to an event. In fact, it only shows the last post of a category (named “competition”), as the other posts from that category are automatically closed at a defined time.
By “closed” I mean that they are moved into another category which is a child of the main category “competition”. Subcategory is name “closed”, in this example.
So, I would like to only show the last article from a category, but not the articles from the subcategory.
I would also like to work with categor_name, not ID.
Here is the code which is currently working for the parent category, but still shows posts from the children (or sub-) category.
<?php
query_posts('category_name=competition,-closed');
if (have_posts()) :
$count = 0;
while (have_posts()) :
the_post();
$count++;
if ($count <= 1) :
?><div id="giveAway" class="sidebar shadow">
<a href="<?php the_permalink(); ?>">
<div class="title">
<h2>Competition<img src="<?php bloginfo("stylesheet_directory"); ?>/design/iconLink.png" /></h2>
</div>
<div class="content">
<?php
MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image');
?>
</div>
</a>
</div><?php
endif;
endwhile;
endif;
?>
I thought that the “query_posts(‘category_name=competition,-closed’)” code would exclude the subcategory from the query, but it seems not to work.
Is there any work around?
Séane
]]>I am really not getting this together. I just want to add a custom column to my “events” admin page. I already added the column, however, I cannot seem to get the right command to get the category.
Can someone help me out?
function event_manager_categories_content($column, $post_id) {
global $event;
switch ($column) {
case 'category':
$emcategory = get_term_by('id', $post_id, 'event-categories');
$emcategoryname = $term->name;
echo $emcategoryname;
I really have a problem with all the names in EM. Where do I get all the right names? E.g. for taxonomy I already read “event-categories” but also “EM_TAXONOMIES_CATEGORY”. Which is the right one and how can I find out myself?
– Thanks already.
https://www.ads-software.com/plugins/events-manager/
]]>I have everything working except the categories. I need to be able to list the categories before the post title and be able to assign each one an ID for color coding purposes (which I can do once I can figure out how to get the categories to display in the first place). I’ve tried wp_get_post_categories and wp_list_categories and at this point am back to square one with just the following that works (this works without categories):
function recent_posts_function($atts){
extract(shortcode_atts(array(
‘posts’ => 5,
), $atts));
$return_string = ‘
$return_string .= ‘
‘.get_the_title().’
<img src=”/wp-content/uploads/2015/01/post-date.jpg” border=”0″ style=”float: left; padding-right:5px;”>’.get_the_date().’
‘;
endwhile;
endif;
$return_string .= ‘
‘;
wp_reset_query();
return $return_string;
}
function register_shortcodes(){
add_shortcode(‘kapitall-recent-posts’, ‘recent_posts_function’);
}
add_action( ‘init’, ‘register_shortcodes’);
I’d appreciate any feedback on how to get categories pulled into this (there may be several categories for one post). Thanks in advance for any tips you can provide.
]]>I have the archive page (the main category), then I’ve posts inside that category and inside the posts I’ve more categories (custom type category).
– Archive (Something w/ Posts about This, This, That)
— Category (Something)
— Posts (about Something)
—– Custom Type Categories (Posts of This, This, That)
What I want is, get all the custom categories inside the posts from that category and put a list inside the archive page.
What I find is how to list all of the custom categories, but I just want the ones given to the posts inside the main category.
I would like to have answers, and really would appreciate to anyone that helps me with this.
I had the best solution to my question, but unfortunately I played with my sidebar last night, and somehow deleted the widget content, so I can’t recall where did I take the php snippet from. Anyways, what I am trying to do is simply call specific categories (I remember that I input their id numbers, separated by comma) to show in unordered list. I managed to find a cached copy of my sidebar before I screwed it up. I made a snapshot – take a look here – https://www.radevtrade.com/Category.jpg
So as you can see, at the back – the little brackets it shows how many post are contained per category. Basically once people click on the category – it takes them to the category permalink, where people can see all the posts. Anyone have the snippet in their pocket I would be veery very thankful if you can help me out with that!
Thanks guys
Regards.
]]>https://www.ads-software.com/extend/plugins/media-categories-2/
]]>In a nutshell, my problem is this –
I have a custom post type, and on the single pages I originally wanted to have Next / Previous posts that would only navigate through the category that the post is in. For some reason, when I set the argument for “in_same_cat” to ‘True’, the Next / Previous links didn’t appear at all.
I couldn’t figure out why this was happening, so I opted to go for a link simply saying “See all posts in this category” and I intended to use WordPress’ get_the_category or posted_in functions – neither of which worked. I’m totally, totally stumped on why these wouldn’t work so any help at all, really appreciated.
Cheers,
-Dave
<?php
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// CUSTOM POST TYPE - Cases
/////////////////////////////////////////////////////////////////////////////////////////////////////////
add_action( 'init', 'create_cases' );
function create_cases() {
register_post_type( 'cases',
array(
'labels' => array(
'name' => __( 'Cases' ),
'singular_name' => __( 'Cases' ),
'add_new' => _x('Add new Case', 'Case item'),
'add_new_item' => __('Add new Case'),
'edit_item' => __('Edit Case'),
'new_item' => __('New Case'),
'view_item' => __('View Case'),
'search_items' => __('Search Cases'),
'not_found' => __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
),
'supports' => array('title','editor','thumbnail'),
'public' => true,
'exclude_from_search' => false,
'hierarchical' => true,
'_builtin' => false,
'capability_type' => 'post',
'has_archive' => true,
'rewrite' => array('slug' => 'case', 'with_front' => false),
'query_var' => true,
'permalink_epmask' => EP_PERMALINK,
)
);
}
register_taxonomy("casetaxonomy", array("cases"), array("hierarchical" => true, "label" => "Lawyer", "singular_label" => "Lawyer", "rewrite" => array("slug" => "casetaxonomy")));
add_action('save_post', 'save_cases');
function save_cases(){
global $post;
}
?>
function losl_posted_in() {
// Retrieves tag list of current post, separated by commas.
$tag_list = get_the_tag_list( '', ', ' );
if ( $tag_list ) {
$posted_in = __( 'This entry was posted in %1$s and tagged %2$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'losl' );
} elseif ( is_object_in_taxonomy( get_post_type(), 'category' ) ) {
$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'losl' );
} elseif ( is_object_in_taxonomy( get_post_type(), 'casetaxonomy' ) ) {
$posted_in = __( 'This entry was posted in %1$s. Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'losl' );
} else {
$posted_in = __( 'Bookmark the <a href="%3$s" title="Permalink to %4$s" rel="bookmark">permalink</a>.', 'losl' );
}
// Prints the string, replacing the placeholders.
printf(
$posted_in,
get_the_category_list( ', ' ),
$tag_list,
get_permalink(),
the_title_attribute( 'echo=0' )
);
}
endif;
<div class="columns eight">
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
<p class="date"><?php the_time('F jS, Y'); ?></p>
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
<?php losl_posted_in(); ?>
<?php get_the_category() ?>
<hr />
<div class="row">
<div class="columns seven">
<p><a href="<?php echo home_url( '/' ); ?>case/">See all of our cases</a></p>
</div><!--columns seven-->
<div class="columns five social-buttons">
<?php // share button ?>
<?php include(get_template_directory() . "/share-button.php"); ?>
</div><!--columns five-->
</div><!--row-->
<?php endwhile; // end of the loop. ?>
</div><!--columns eight-->
]]><?php
$category = get_the_category();
if($category[0]){
echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';
}
?>
Just wondering, how can I add an if conditional statement in that (sorry not too PHP savvy):
<?php if (is_category('blogging')) { ?>
Make Money Blogging
<?php } else { single_cat_title(); } ?>
Basically, I want it to just get the post category URL linked by not the category name but my own defined name. So, for example, if the post is in the “blogging” category, I want it to link to that category page but with “Make Money Blogging” rather than just “Blogging” and I want to do this for more than just that one category, want to do that for two categories.
Also, if possible, set a conditional statement so that if someone is browsing the category “Blogging” than the category name is not linked at all (but this is just if its possible — not really necessary).
Hoping for a prompt response, thank you!
]]><a href=" ">
to use it to bring up information page for those videos.
Example:
anime/series <- Information page of the anime series
anime/series/episode-104 <- Episode of the series
I basically need just anime/series to place itself in a <a href="">
so i do not have to do it manually for every page. And since wordpress has a get_category function im sure this can be done i just do not know how.
If I do
$category = get_the_category();
inside of a subcategory and then do
$category[0]->description
This should return the description of the CURRENT category correct? It seems that WordPress is organizing parent/child category relationships alphabetically for me, which seems really silly. Has anyone else noticed this?
Thanks
]]>