Forum Replies Created

Viewing 15 replies - 1 through 15 (of 57 total)
  • Thread Starter antistandard

    (@antistandard)

    @brasofilo – this is only a snipet of code that I had first made to work in a template php file. Then I wanted to see if I could make it into a shortcode function and that is why it looks like it does not reference anything, but when the shortcode gets triggered, this shortcode block relates to other code inside the post/page that it sits in and seems to work fine. Thank you for that inquiry.

    @alchymyth – I seem to remember you helping me once before. Thank you very much for your fix. IT WORKS! and now I can learn from you how to make that array output. Thanks again for your help and accuracy.

    Thread Starter antistandard

    (@antistandard)

    Sure, sorry that is new to me.

    Code:

    https://pastebin.com/eRmCBLyQ

    Thanks

    Thread Starter antistandard

    (@antistandard)

    ok great thanks, I’ll try it out when i get a chance and let you know how i go

    Thread Starter antistandard

    (@antistandard)

    By the way, before I close this post down, would you happen to know how to re-order the get_the_category() call so that it displays in an order I can set using a plugin such as ‘category order’ or ‘my category order’ ?

    Thank you

    Thread Starter antistandard

    (@antistandard)

    In addition I was hoping to also re-order the categories so they display in some manual way that I can set using a plugin or such.

    Thank you

    Thread Starter antistandard

    (@antistandard)

    Ok Thanks Emil, I’ll head over to the link you gave me. Sorry to go against www.ads-software.com guidelines.

    Thread Starter antistandard

    (@antistandard)

    Thanks Alchymyth, you know your php ??

    It works well, here’s my code:

    <? query_posts('cat=5&order=DESC');
    		if ( have_posts() ) : while ( have_posts() : the_post(); 
    
    		?>
    		<p class="whosrunning"><?php the_title(); ?></p>
    		<?php
    foreach((get_the_category()) as $childcat) {
    if (cat_is_ancestor_of(9, $childcat)) {
    echo $childcat->cat_name;
    }}
    
    		endwhile; else:
    		echo "No members have events coming up at the moment";
    		endif;
    ?>

    but do happen to know how I can modify this query to ONLY show posts that have category 9 cats associated with them?

    in other words, if a post exists, but does not have any category 9 cats ticked in it’s edit screen, I don’t want to show it.

    Thanks again for all your help

    James

    Thread Starter antistandard

    (@antistandard)

    after re-reading this question I thought it might sound confusing.

    To make it easy to explain,

    I want to list all the posts in a category.

    Just say there are 3 posts in category ‘animals’

    Now, with each of the 3 posts in ‘animals’ category, i want to show what categories they are associated with.

    So, the first post in the ‘animals’ category might have ‘dogs’ and ‘fish’ associated with it.

    and the second post might have the ‘fish’ ‘birds’ and ‘insects’ category associated with it.

    so it would look like

    Post title 1
    – dogs category
    – fish category

    Post title 3
    – fish category
    – birds category
    – insect category

    post title 4
    – birds category
    – dog category

    At the moment my code looks like:

    <? query_posts('cat=5&order=DESC');
    		if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    		<p class="whosrunning"><?php the_title(); ?></p>
    	    <? wp_list_cats('child_of=9');
    		endwhile; else:
    		echo "No members have events coming up at the moment";
    		endif;
    ?>

    which lists all posts in the ‘animals’ category but unfortunately lists out all the categories which are children of animals.

    what i want to happen is for the loop to look at each post individually and only show the categories that that particular post is associated with and then look at the next post etc etc.

    Thank you for you time

    James

    Thread Starter antistandard

    (@antistandard)

    Thanks again vtxyzzy,

    I understand what you mean now.

    If I was to then reverse sort the value instead of the keys, would i use:

    natsort($custom_field_values);
    $custom_field_values = array_reverse($custom_field_values,true);

    thank you for your time and help
    -james

    Thread Starter antistandard

    (@antistandard)

    Hi vtxyzzy for your help.

    I was lookiing and didn’t find any documentation on ‘rsort’ in the wordpress codex.

    are there any parameters i can use with it to sort alphabetically, or by value ?

    It would be perfect if I can sort the keys by value like in my example where the highest number (in the example 6 dragons) is first in the sorted output, then 3 bees and lastly 2 crocodiles.

    hope that makes sense.

    What I am trying to acheive is to sort the keys by using a number in the value field. So my client can put the highest number in the value for the key they want to appear first and so on..

    Thanks for your help

    Thread Starter antistandard

    (@antistandard)

    Great, thanks. I tried that and the result was that it returned the sub cat title instead of the post title, but I found a different way to display the post title using custom fields.

    Thanks again on your help. I really do appreciate it

    James

    Thread Starter antistandard

    (@antistandard)

    Hi Alchymyth,

    Thank you sooo much.

    Your function worked really well as a base for what I am doing. I really appreciate your help and your code is excellent.

    I had to edit a few things for formatting (of course) but the core code was perfect. Thank you !!

    The only thing I could not work out was how to list the post title. When I used <? echo single_post_title(); ?>, it returned the sub cat title instead.

    You have helped me more than enough with this so I don’t expect you to help me anymore, but ofcourse, if it is simple to solve I’d love to hear the solution.

    Thanks again,

    You rule

    James

    Thread Starter antistandard

    (@antistandard)

    Hi alchymyth,

    Thank you for the function.

    I will try it this weekend and tell you how I go.

    Thanks again,

    James

    Thread Starter antistandard

    (@antistandard)

    Hi Keesiemeijer,

    Yes, that worked, thank you very much.

    I didn’t need the lines:
    // get all posts with a custom field key “name”
    query_posts(‘meta_key=name’); ?>

    but everything else was perfect.

    James

    Thread Starter antistandard

    (@antistandard)

    Thanks mate, I’ll look at this later this weekend and let you know how I go.

    Thanks again for your time,

    James

Viewing 15 replies - 1 through 15 (of 57 total)