Child page for every category Wordpress - wordpress

I create in my wordpress theme template page named popular.php, where i sort post by popularity. It works fine for every post but I dont know how to do this for category.
I want something like this:
sitename.com/popular-post - works fine
sitename.com/category-name/popular-post - i don't know how to make popular page child for every category?
Popular loop works fine with this args:
<?php $current_category_ID = getCurrentCatID(); ?>
<?php $args = array(
'posts_per_page' => 60,
'cat' => $current_category_ID,
'meta_key' => 'views',
'orderby' => 'meta_value_num',
'order' => 'DESC',
); ?>
<?php query_posts($args); ?>
Only I don't know make it child for category?

Check Permalink Settings & update the custom structure like this
/%category%/%postname%/

https://codex.wordpress.org/Category_Templates
See this page in the codex. It explains how to name your template files for category.
For example, if you have a file in your theme named category.php, that template will be used to display a category page.

Related

Show Child post of Specific Parent on any page in Wordpress

I want to be able to use a shortcode to list a child post for a specfic parent on any page (custom post types mainly).
I found this: Show Child-pages of Specific Parent on any page in Wordpress
and it's perfect, but only for "pages" I think, it is not working for me with Custom Post Types.
Guillem,
You can keep use the code from this link.
Just add your custom post types in wp_list_pages function.
So, you will have:
$childpages = wp_list_pages( array(
'child_of' => $post->ID,
'title_li' => '',
'post_type' => 'YOUR_CPT_SLUG',
'echo' => 0,
) );

Can I use WP_Query to return pages by category?

I'm creating a WordPress site for a theater. I have several performer pages featuring performers with images, bios, etc. I would like to feature one performer on the homepage as a "Featured Performer." I created a category in pages called "Featured-HP." I am trying to return just this one performer to use on the homepage. It is not working at all. Can this even be done?
Here is my code:
$args = array(
'post_type' => 'page',
'category' => 231,
'posts_per_page' => -1
);
// The Query
$featured_performer = new WP_Query( $args );
Then to display it...
while ( $featured_performer->have_posts() ) :
$featured_performer->the_post();
// CODE HERE TO SHOW IMAGE AND NAME
endwhile;
Nothing gets returned, though, so, I haven't even gotten to the image and name. Any help or advice would be appreciated. Thanks!
One of the category parameters in WP_Query is cat for single category id. So instead of category replace it with cat.
As follows:
$args = array(
'post_type' => 'page',
'cat' => 231,
'posts_per_page' => -1
);
You can also dig in a little bit deeper into the Category Parameters

Is there any way I can add category ID in the URL of a Page in WordPress?

I have a page that lists posts from a specific category.
Now I need to add another page which needs to list posts from another category.
I could just create a copy of the template that the working page is using and just change category ID.
But since everything else in the template is the same it would probably be better if both pages use the same page template and the category ID is obtained from the URL.
There is probably a way to achieve this but I'm not sure how.
You can add a Custom Field in the page : cats = "1,2,3"
then in page template :
$custom_cats = get_post_custom_values('cats');
$args = array(
'category' => $custom_cats[0], //like: 1,2,3
'orderby' => 'post_date',
'post_status' => 'publish',
);
$query = get_posts( $args );
This is the same page template.

wordpress - excluding a category from a post list in a custom theme that doesn't look like the codex

I'm hoping someone can help. I'm not a php coder, but I've been tweeking and customising a premium theme for wordpress anyway, and I'm stuck.
I'm trying to exclude a specific category from a page which lists all the categories by default. Ok, no problem. It should be:
<?php query_posts($query_string . '&cat=-134'); ?>
right?
I'm pretty sure the category number is 134, but I could be wrong. The premium theme I'm using is called Risen, and there's a lot of different kinds of posts - so maybe what I think is a category is really a tag in a custom taxonomy - in which case ???
When I hover over it in the category listing I get this:
example.com/wp-admin/edit-tags.php?action=edit&taxonomy=risen_multimedia_category&tag_ID=134&post_type=risen_multimedia
I'm pretty sure I've found where I need to include my argument, and that is here in the template:
// Get posts
$multimedia_query = new WP_Query( array(
'post_type' => 'risen_multimedia',
'posts_per_page' => risen_option( 'multimedia_per_page' ) ? risen_option( 'multimedia_per_page' ) : risen_option_default( 'multimedia_per_page' ),
'paged' => risen_page_num() // returns/corrects $paged so pagination works on static front page
) );
I've tried adding
'tag' => -134
to this array to no avail.
Being a premium, and apperently tweaked, theme there is a lot of guessing here but I think you have talked yourself into the solution, except for one detail. Use tag__not_in not tag=-134
// Get posts
$multimedia_query = new WP_Query( array(
'post_type' => 'risen_multimedia',
'posts_per_page' => risen_option( 'multimedia_per_page' ) ? risen_option( 'multimedia_per_page' ) : risen_option_default( 'multimedia_per_page' ),
'paged' => risen_page_num() // returns/corrects $paged so pagination works on static front page
'tag__not_in' => array(134)
) );
tag_id=-134 might work (I'd have to test it) but tag expects the tag slug not an ID.
tag (string) - use tag slug
http://codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters

How to fetch all WordPress posts with featured image?

In WordPress 3 there is Featured Image functionality. How do i fetch all posts that have a featured image with them? Here is my current custom loop:
$loop = new WP_Query( array( 'posts_per_page' => 15 ) );
This should work:
$loop = new WP_Query( array( 'posts_per_page' => -1, 'meta_key' => '_thumbnail_id' ) );
I haven't tested this, though. Also, this will probably fetch all posts and pages. Use 'post_type' => 'post' to limit it to blog posts.
I don't believe you need any special loops defined for that to work.
Though you do need to add some small snippets into your functions.php
like this one:
<?php add_theme_support ( 'post-thumbnails' ); ?>
after apply the above code to functions.php file, your theme will support Featured Images and you will see a new link # the bottom right of your Post Add / Edit interface.
This guide will help you, if you are looking for more info regarding this : How to Use Wordpress Featured Image Feature

Resources