How can I get Wordpress archives by author username? - php

I need to get archives of one author and exlude all others, Wordpress wp get archives() doesn't have that kind of filter. How can I fitler all other others except one author from archives?
http://codex.wordpress.org/Template_Tags/wp_get_archives
<?php wp_get_archives('type=monthly'); ?>

Just off the top of my head:
get_posts(array('author_name' => 'the_authors_name'))
You don't get anything preformatted like from wp_get_archives, just the list of posts, but you get the posts by author. If you need to do more fancy things or want to run a WP Loop you can do a custom WP_Query object as well.

Related

If URL x, load template, else single.php (on Wordpress)

I have custom posts that I want to be shown in a different template.
Right now I have custom posts on:
www.mywebsite.com/travel/post-name
All other (default) posts are on:
www.mywebsite.com/post-name
Basically, I'm trying to find a function.php code, that identifies URL and applies another template.
So, if path www.mywebsite.com/travel/post, then load post in traveltemplate.php
else, single.php
Any help would be appreciated.
P.S. this is not categories, so in_category category ID and category won't work.
I'm looking for a rough url identifier.
WordPress has a pretty sophisticated system to pick the “correct” template for specific pieces of content already, based on certain file naming patterns.
Check https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/, it explains how that looks for custom post types.
single posts of a custom post type will use single-{post_type}.php
and their archives will use archive-{post_type}.php

Showing taxonomies in Wordpress

I have a Wordpress site with three custom taxonomies. They're configured and working, with some posts marked with each, and want to run code related to them. As per the documentation, if the custom taxonomies are cats, dogs and trees, and I want to run php about cats, after lots of trying and going up and down over the documentation, I think I should create a template and call it "taxonomy-cats.php":
taxonomy-{taxonomy}.php: For example, if the taxonomy is named “sometax,” WordPress would look for a file named taxonomy-sometax.php
But I still don't get something: the docs say "wordpres would look for". Why would WP look for it and not other? I suppose I at least have to tell it what or when to search for it. How or where do I tell WP to look for it?
<?php /* Template Name: Taxonomy cats */
get_header(); ?>
<h1>Hello world</h1>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
As a template, I've found I can add it in the administration as an attribute to a post, but then when I enter that page if I try to get the id of the taxonomy, I get the id of the post.
Wordpress uses a loop to display posts. Wherever you are, most of time, the loop is being used.
The Loop is PHP code used by WordPress to display posts. Using The
Loop, WordPress processes each post to be displayed on the current
page, and formats it according to how it matches specified criteria
within The Loop tags. Any HTML or PHP code in the Loop will be
processed on each post.
Source # https://codex.wordpress.org/The_Loop
Wordpress is also based on a template hierarchy system. With the exception of the basic index.php template file, you can choose whether you want to implement a particular template file or not.
WordPress uses the query string to decide which template or set of
templates should be used to display the page. The query string is
information that is contained in the link to each part of your
website.
You can take a look at this image to have a visual understanding of the Wordpress templates hierarchy.
Source # https://developer.wordpress.org/themes/basics/template-hierarchy/
In your case when displaying the dogs taxonomy, Wordpress look for the following files in that order: taxonomy-pets-dogs.phpif this template doesn't exist it move on to look for pets taxonomy-pets.php, if it doesn't exist it moves on to taxonomy.php... etc
(Where pets is the name of your taxonomy and dogs is a term inside that taxonomy)
Specifying taxonomy-pets-dogs.php enables you to create a custom template for that specific term. cats wont have the same template as dogs exept if both are using taxonomy.php or taxonomy-pets.php and if no specific templates exist.
But in any case taxonomy-{taxonomy}.php or taxonomy-{taxonomy}-{term}.php will always use the loop to display posts and terms. Like any other template.
<?php if ( have_posts() ) :
while ( have_posts() ) : the_post();
echo the_title().'<br/>';
endwhile; else :
echo 'No posts found!';
endif; ?>

Wordpress categories list RSS feed

I am developing an iOS App for a blog. I managed to parse the posts and their content using the RSS feed, that Wordpress provides.
Now, i want to get an RSS feed of categories, so when an user selects a category, to display that category's posts. According to the Wordpress codex, there is a way to retrieve all the posts from a category, but how can i get a list of categories, maybe with an identifier or something so i can get all the posts based on that.
Thanks in advance.
Why not try making use of get_categories()? You could parse that into an xml feed, and expose it at http://yoursite.com/category-rss/ for your app.
I know I'm late to the party, but any custom theme dev's out there that are looking for a PHP way to easily do the same... this worked great for me:
href="<?php bloginfo('rss_url'); ?><?php echo('?cat=XXX'); ?>"
Where "XXX" is the category ID for the respective category you wish to pull in.

how to show different post of different category on different pages in wordpress?

I am working with wordpress theme , I want to show posts on different pages according to category .
for example page name is "Blog" and post category is postBlog, can you tell me how I can use post according to category .
Thanks
What are you trying to do can be achieved with WordPress Category Template.
From the Codex:
For instance, when a viewer clicks on a link to one of the Categories on your site, he or she is taken to a page listing the Posts from that particular Category in chronological order, from newest Posts at the top to oldest at the bottom.
You can create a file in your theme, called: category.php, put a loop inside of it and then WordPress will automatically do that for you.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
And then fill your needs with the page. You can check the documentation for The Loop here in this link.
create a template category-catname.php or category-catID.php in your theme dir.
See http://codex.wordpress.org/Category_Templates
I think people get confused trying to use Pages when they are actually better off using Categories. If you want to have blog posts show up on different URLs or 'pages' then all you have to do is set up your categories and put those categories into you Menu. Then when you post make sure to select which categories you want that post to show on. You don't have to use pages at all. Pages are better for static content.
Good luck, I hope this helps.

Display taxonomy terms for current post only (Drupal)

I have many snippets to show all taxonomy terms. However, I want to be able to list all taxonomy terms for the current post that you're readying (with links behind them to see more posts tagged with that same term).
Any ideas?
Most drupal stock templates show the nodes terms in the node display by default, if you're not seeing them perhaps your template doesn't expose them in your node.tpl.php like so:
<?php if ($taxonomy): ?>
<div class="terms"><?php print $terms ?></div>
<?php endif;?>
OR...
You may be using views with field display/row style and need to add the taxonomy terms as a field

Categories