Forum Replies Created

Viewing 15 replies - 1 through 15 (of 44 total)
  • Thread Starter specialmachine

    (@specialmachine)

    For anyone’s future reference, the code works in both manners as you would assume…

    <?php
    	$args=array(
    		'orderby' =>'parent',
    		'tag_slug__in' => array('food','cocktails','wine'),
    		'order' =>'asc',
    		'post_type' =>'page'
    		);
    	$page_query = new WP_Query($args);
    ?>
    
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    	<div class="teaser">
    	<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    	<?php the_excerpt(); ?>
    	</div>
    <?php endwhile; ?>

    or…

    <?php
    	$args=array(
    		'orderby' =>'parent',
    		'tag_slug__in' => array('menu'),
    		'order' =>'asc',
    		'post_type' =>'page'
    		);
    	$page_query = new WP_Query($args);
    ?>
    
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    	<div class="teaser">
    	<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    	<?php the_excerpt(); ?>
    	</div>
    <?php endwhile; ?>

    So, a nice use for this code could be displaying pages in a single template, like if you have a menu with three sections (food, cocktails, wine). So you can tag them all “menu” and use just that tag in the code, or you can control the order in an arbitrary way by listing the tags in the array.

    Thank you again to Hakkim. I’m really happy to know there are kind people out there, willing to help. It’s really cool.

    Thread Starter specialmachine

    (@specialmachine)

    Boom! That works! THANK YOU! Now I have two very useful bits of code. Lots of love from Germany, Hakkim!

    Thread Starter specialmachine

    (@specialmachine)

    Ah, just saw your new post. I’ll try it.

    Thread Starter specialmachine

    (@specialmachine)

    In this case, would it be looking for a page that is tagged, ‘essen’, and ‘trinken’ and ‘wein’?

    Sorry. I’ve realized I can just tag all three pages with ‘menu’ and as they are set to order anyway, it really achieves what I’m after.

    That said, ideally, it would be great to be able to have an arbitrary order for design purposes. But this achieves what I’m after, so I do thank you. The reason I was after a way to display pages by slug was so I could just list them in the order I wanted them to appear, along with not having to fuss over an ID as they are often if ever in sync unless the databases are exactly the same between what’s online and my local machine where I build the sites.

    So thank you for your help. We can leave it there if you like. Perhaps some day I’ll achieve my dream. ??

    Thread Starter specialmachine

    (@specialmachine)

    Thanks for sticking with me, Hakkim. I really appreciate it.

    This is currently the code I’m using, after having removed the comma after ‘post_type’ =>’page’

    It seems to only work with a single tag. If I add more than one, it stops working and nothing displays, although it doesn’t break the page.

    <?php
    	$args=array(
    		'orderby' =>'parent',
    		'tag' => 'essen+trinken+wein',
    		'order' =>'asc',
    		'post_type' =>'page'
    		);
    	 query_posts($args);
    	$page_query = new WP_Query($args);
    ?>
    
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    	<div class="teaser">
    	<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    	<?php the_excerpt(); ?>
    	</div>
    <?php endwhile; ?>
    Thread Starter specialmachine

    (@specialmachine)

    Sorry, I was using this….

    <?php
    	$args=array(
    		'orderby' =>'parent',
    		'tag' => 'essen+trinken+wein',
    		'order' =>'asc',
    		'post_type' =>'page',
    		);
    	 query_posts($args);
    	$page_query = new WP_Query($args);
    ?>
    
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    	<div class="teaser">
    	<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    	<?php the_excerpt(); ?>
    	</div>
    <?php endwhile; ?>
    Thread Starter specialmachine

    (@specialmachine)

    Okay, I enabled tagging for pages by grabbing some code here and slapping it in my functions.php. I tagged each page with the corresponding name, so just like the slug names. Then I tried to add in your code with the updates to the tag names and it broke the page. Again, lack of understanding for how this works. Sorry. This is the code i’m trying to use now…

    <?php
    	$args=array(
    		'orderby' =>'parent',
    		'tag' => 'food+cocktails+wine',
    		'order' =>'asc',
    		'post_type' =>'page',
    		);
    	 query_posts($args);
    ?>
    
    <?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    	<div class="teaser">
    	<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    	<?php the_excerpt(); ?>
    	</div>
    <?php endwhile; ?>
    Thread Starter specialmachine

    (@specialmachine)

    Hi Hakkim – I really don’t know how to do any of this. I’m not a developer. I know what I’m after, and then when it comes to how to do it, I just scour the web looking for a snippet of code.

    Thread Starter specialmachine

    (@specialmachine)

    Yes, wonderful – I can do it with one slug, but I’m after multiple slugs. Perhaps I’m just not doing that part right as this code breaks the page…

    <?php
    					$the_slug = 'food', 'cocktails', 'wine';
    					$args=array(
    						'orderby' =>'parent',
    					        'name' => $the_slug,
    						'order' =>'asc',
    						'post_type' =>'page',
    						);
    					$page_query = new WP_Query($args);
    				?>
    
    				<?php while ($page_query->have_posts()) : $page_query->the_post(); ?>
    					<div class="teaser">
    					<h2><a href="<?php the_permalink();?>"><?php the_title();?></a></h2>
    					<?php the_excerpt(); ?>
    					</div>
    				<?php endwhile; ?>
    Thread Starter specialmachine

    (@specialmachine)

    I found some documentation. I guess I just have to bite the bullet. Arrghghg.

    Do you have a url?

    Thread Starter specialmachine

    (@specialmachine)

    I really appreciate your trying. I did trying to adapt the other code to this, but had no luck myself.

    Thread Starter specialmachine

    (@specialmachine)

    I’ve even excluded “uncategorized” (or “Uncategorized” if it’s the category name version) so that is why there are no categories at all. There are only three categories in total at the moment, and I don’t want any of them to display. As I add posts, I will add additional categories, obviously, and each of the existing posts will get some category that will display as well, but it’s good that this popped up like this as it shows there’s a bug when there is no category assigned (other than “uncategorized”).

    Thread Starter specialmachine

    (@specialmachine)

    Sorry it’s only local at the moment.

    I created a child theme of Twenty Twelve with no changes to this particular function that displays the meta entry at the footer of the post, both in the index.php and single.php, other than the code we have both posted in this thread. Each result is the result of using that code independently – I am using either the snippet I posted, or yours. Not both at the same time.

    Here are the differences…

    ***

    This entry was posted on 3. June 2013.

    This entry was posted in , on 3. June 2013.

    ***

    The first is a result of using the category name code. The second is the result of your snippet. You can see in the first result, the default behavior coded into the twentytwelve_entry_meta function kicks in so what’s displayed is tidy in the absence of a category.

    Thread Starter specialmachine

    (@specialmachine)

    Very nearly. I really appreciate the effort. You can see how its behaving here with these two screens. One is using the category names, which is the first screen capture, and the second is using your code. The former displays a tidy category free version when there are no categories present as all three of the existing categories have been excluded.

    https://cl.ly/image/451E1Y3G1f2m

    https://cl.ly/image/2247241y0w2z

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