Wordpress . How to move some post from front page to a different page? - wordpress

I have 40 or so post on a WordPress site.
I need to move about 20 of them to a new page I created.
I have created to (New) page and a new category for these post.
I changed edit some of the post and changed the category to the new one.
They show up on the (New) page , but they all so show up on the Front page as well.
What needs to be done to get the post to just show up on the (New) page and not the Main page of the site.
Thanks for your help.

Exclude that category from the front page like so:
if ( is_front_page() ) { query_posts( 'cat=-1' ); }
Switch out the "1" with the ID of the category you want to exclude. The - sign in front of the ID says it is excluded.
Reference: WordPress Codex: Query Posts

Related

How to add a child page to a Custom Post Type "Post"

Friends, Hello.
I have an issue, i'm searching for an answer for 2 days now. I think I have checked all the 10 firsts google pages of 20 different requests by now.
So, this is it.
I have a custom post type named "Footballer".
I have created 2 "Posts" of that CPT, which are "Messi" and "Ronaldo".
My permalinks for these 2 footballers are "mysite.com/footballer/messi/" and "mysite.com/footballer/ronaldo/". It is OK for me.
Now, I want to add a child page "about" (or "stats", or anything) to my footballers and I want this page to be available by the link "mysite.com/footballer/messi/about" (just add the child page slug after the cpt post link).
Obviously, I want to create a single page "about", not one for every footballer I have, and in this page I would retrieve data for the specific footballer (by functions/shortcodes).
Nota: the cpt and values in this post are fictionnals, I know I would display the about/stats directly in the footballer cpt post. I am just trying to explain what I need -> a generic child page for a cpt, available by "mysite.com/cpt/cptpost/childpage".
How can I do it ? I s it even possible ?
Thanks for your help.
EDIT ;
As it is not possible with Divi, can I try to rewrite the URL of my subpage ? If my subpage url is "mysite/subpage/?foot=messi", can I make it appear "mysite/footballer/messi/subpage".
I tried this code, without success
function my_rewrite_url() {
add_rewrite_tag( '%foot%','([^&]+)' );
add_rewrite_rule(
'footballer/([^/]+)/subpage',
'index.php?pagename=subpage&foot=$matches[1]',
'top'
);
}
add_action( 'init', 'my_rewrite_url' );
You are looking for custom taxonomies on the custom post type.

Woocommerce product archive displays nothing when called from custom Page

I have a woocommerce shop page which shows me all of the products perfectly. This page is also set as the "Shop" page in the settings. Now I want a second page called Home, which should use the same template as the shop page. (basically a second shop page without categories and some news)
home-template.php
<?php /* Template Name: Homepage */
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
wc_get_template( 'archive-product.php' );
?>
I'm using the standard archive-product template from woocommerce's github.
I can see the template being loaded, like the header, but certain woocommerce functions don't return the expected value. woocommerce_before_shop_loop doesn't return anything, even though it should display the orderby dropdown. woocommerce_product_loop() returns true, but wc_get_loop_prop('total') returns zero.
I've also tried renaming the file to front-page.php but that didn't help. The home page is set correctly in the reading settings.
Am i missing a call to a query, or is it something else? Thank you in advance for your help!
When WooCommerce creates the builtin shop page it saves the id of the created page in the wp_options database table with option_name 'woocommerce_shop_page_id'. When WordPress loads a page WooCommerce checks if the page id of the page being loaded is equal to the option_value of option_name 'woocommerce_shop_page_id' and then executes code to generate the HTML of the shop page. If you have looked at the shop page in the page editor you will notice that the content is empty. The magic is being done with hard coded routines that execute for this special id.
Since, your custom page has a different page id none of the custom code for generating the shop page will be execute. So, you need to execute this magic code for your custom page. It can be done but you need a good understanding of WooCommerce.
I suggest you reconsider your design and instead of a new page just customize the existing shop page using actions and filters.

Replacing Wordpress Category with Static Page?

I'm rehashing a Wordpress question from 4 years ago that had an approved answer, but that solution no longer works in the current version of Wordpress. The original question: Make Wordpress use the page instead of category
Background (copied from originally approved answer):
example.com is the domain
I have a WP page called "foobar" with content
I have a WP post category called "foobar"
I have a WP post entitled "fun things to do with foobars", and the category is set to "foobar"
Expectations
When I go to example.com/foobar, I want to see the page about foobars, not a WP category page that shows all blog posts with that category.
When I go to the blog post about fun things, the URL is example.com/foobar/fun-things-to-do-with-foobars/
The solution at the time
There appeared to be a work-around with a custom permalink structure and using "." (no quotes) as the category base. That solution does not work with the current version of Wordpress.
There were also a couple of answers that suggested various plugins. I'm not overtly opposed to that route, but the suggested plugins at the time seem to have been affected by the same update that negated the accepted answer.
To load page with the same slug as of category name you could use following code snippet that replace category with Page.
function wpa_alter_cat_links( $termlink, $term, $taxonomy ){
if( 'category' != $taxonomy ) return $termlink;
return str_replace( '/category', '', $termlink );
}
add_filter( 'term_link', 'wpa_alter_cat_links', 10, 3 );
Be aware with the code. You should have pages for all your categories otherwise you will get 404 for those categories which have not created pages.
After adding above code into your activated theme's functons.php file please flush the permalink. You can do that with visiting settings -> permalinks -> click save changes
Hope it works for you!

How to disable template files in single page wordpress theme

I am creating a single page Wordpress site and I would like disable/delete/remove all other pages so that they just return a 404.
So if the user tries to go to an archive page or a single post page it does not work. I only want one working page on the entire site.
You can simply force all pages to be redirected to the front page by putting the following code in your functions.php:
function redirect_to_homepage() {
if ( ! is_front_page() ) {
wp_redirect( home_url( '/' ), 302 );
exit;
}
}
add_action( 'template_redirect', 'redirect_to_homepage' );
Just a quick note: is_front_page() checks if the user is trying to access the page that is set for the front page in Settings > Reading. If no such page is set, use is_home() instead.
Reference:
http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
http://codex.wordpress.org/Function_Reference/is_front_page
http://codex.wordpress.org/Function_Reference/is_home
Instructions for what I think you want to have done. This will remove all other pages/posts, and make the page you did not delete into the home page of your website.
Log into your site
In the admin panel go to pages
Select all of the pages except the one you want to keep as the home
In the "Bulk Actions" select move to trash and click apply
Go into the trash section of pages
Select all of the pages
In the "Bulk Actions" select move to delete permanently and click apply
Repeat steps 2-7 for the "posts"
Go to the settings reading page in the admin panel
Check off static page
In the front page drop down select the page you did not delete
Click save at the bottom of the page.

fetch registered user posts in wordpress

I am making a wordpress website on which the main posts are coming on the homepage .
I want that if a user regiters on the website and if he make posts on the website , his/her post should go on a a specific page rather than coming on the homepage where the main admin posts are coming .
how to fetch the registered user posts to a specific page .
Please help if anyone can .
Thanks in advance
You can try specifying the author ID. For content-home.php page use
$posts = get_posts('author=1&posts_per_page=1&orderby=date&order=desc');
$post = $posts[0];
If you want to show only the latest post.
And for the other page exclude this ID.
$posts = get_posts('author=-1');

Resources