I am trying to create a series of pages that display posts in the same category. To do this, I use the following PHP code:
& lt ;? Php $ args = array ('category' => '$ CATEGORY', 'numberposts' => 10000000000); $ Myposts = get_posts ($ Args); Forex Currency ($ myposts $ as post): setup_postdata ($ post); ? & Gt;
My problem is that $ CATEGORY does not have a category as a string. I have tried to use both% s and $ id but as I have not declared that this is the category id, I want it to fail to work.
How will the class string be expressed?
Below is a page with problem that shows the problem. This is a category page, which means that it should have all the necessary information. If this was working then it would only show the most posts because it is the only site in which there is a "press release" category. It is worth mentioning that I have another page, like it is called "document" and it displays the press release.
edit
< P> I did not pay attention to this before, but it seems that you are using the bundle theme twelfth. Just remove category.php from the subject of your child. If you have made changes in the original theme straight away, you should get a new copy of the theme, and create one with all your modifications, never change the theme that you did not write When such a theme is updated, whatever changes you make will run forever You will only need the pre_get_posts
section for your code
Your problem is only your custom loop As you have been told, you should not use custom queries on any type of archive page or main query on your home page
< P> To resolve this, return to the default loop. You should not have all this get_posts
or foreach loops if (have_posts ()) {while ( Have_posts ()) {the_post (); // Add your loop elements here- _ title () and the_content ()}}
This problem should be corrected when you go to a category page, only seen The category will be viewed, no posts will be shown from other categories
Now, if you need to change anything on your category page, use this conditional tag to use only your category pages To target. You can also target a specific category with this tag
For example, you need to change the post per page on your page, as is your case, all posts without page To display on, you can do your functions. Php
function SO26589648_category_ppp ($ query) {if (! Is_admin () & quot; query- & gt; is_category () & quot; query- & gt; is_main_query ()) { $ Query-> Set ('posts_per_page', '-1'); }} Add_action ('pre_get_posts', 'so26589648_category_ppp');
If you need to change asc
for example and you need to post by the authors, you can do this
function SO26589648_category_ppp ($ is_admin () and & amp; amp; and & quot; query- & gt; is_category () and $ query- & gt; is_main_query ()) {$ query- & Gt; Set ('posts_per_page', '-1'); $ Query-> Set ('order', 'asc'); $ Query-> Set ('orderby', 'author'); }} Add_action ('pre_get_posts', 'so26589648_category_ppp');
You should look for all available parameters to use
Comments
Post a Comment