wordpress one-page website with different php pages - wordpress

I'm trying to build a wordpress website. I'd like to have a one-page design. I have built 5 pages
each one has its own php file. How can I do to concatenate the 5 pages in one single page?
Thank you in advance for your help,
Fabiana

You may not need to use multiple pages at all but implement inbuilt function for wordpress like shortcodes, or use posts and make multiple queries to the post. You can then design your page (1) in sections and make sure to make $loop = new WP_Query( $args ); to enable multiple queries on the same page. These queries would/should only query post not pages.
Section 1 Layout
$args1 = shortcode_atts (array(
'tag' => 'post-type',
'post_type'=> 'post',
'cat' => '', // Category ID
'posts_per_page' => 1,
'bgimageurl' => ''), $atts);
$query1 = new WP_Query( $args2 );
// The Loop
while ( $query1->have_posts() ) {
$query1->the_post();
the_content();
wp_reset_postdata();
Section 2 Layout
$args2 = shortcode_atts (array(
'tag' => 'userchoice',
'post_type'=> 'post',
'cat' => '', // Category ID
'posts_per_page' => 1,
'bgimageurl' => ''), $atts);
$query2 = new WP_Query( $args2 );

You can take a look at this plugin for wordpress which provides a way to create full screen scrolling pages by using fullPage.js plugin.

Related

Sticky posts not showing when using category filter

I am trying to show a specific category post on my home page and in which 1 post is sticky that will appear first but its not working.
I have noticed when I try to show all posts, then sticky post shows first. When I try to show a specific category then its not showing first.
Here is my code:
$sticky = get_option( 'sticky_posts' );
$args = array( 'posts_per_page' => intval($blogtoShow),
'post_status'=>'publish',
'post_type'=>'post',
'cat' => $cattoShow,
'orderby'=>'date',
'post__in' => $sticky);
$the_query = new WP_Query( $args );
if ($the_query->have_posts()) :
while( $the_query->have_posts() ) : $the_query->the_post();```
You're looking for the following:
ignore_sticky_posts (boolean) – ignore post stickiness (available since version 3.1, replaced caller_get_posts parameter). false (default): move sticky posts to the start of the set. true: do not move sticky posts to the start of the set.
If you're using a pre-made theme the default might have been modified.
You should add this to your arguments array: 'ignore_sticky_posts' => 0.
A comma should separate each arguments. (Not tested but should work)
More info on the worpress query: https://developer.wordpress.org/reference/classes/wp_query/
----------
EDIT 1.1: I think you need to display a specific template for the sticky (as it's not considered a normal post). At the begining of your loop can you try the following?
$sticky = get_option( 'sticky_posts' );
$args = array(
'posts_per_page' => 3,
'post__in' => $sticky,
);
$query = new WP_Query( $args );
if ( $sticky[0] ) {
// insert sticky template...
} else {
// insert posts template...
}

Using Customizer to define category_name in Wordpress

I am trying to use the Wordpress Customizer to allow the client to input the category names for post that will appear on the homepage. The design calls for two columns of posts, with definable categories for each column.
My hope is that I could do something like:
if( get_theme_mod( 'column_1_category') != "" );
$args = array(
'category_name' => echo get_theme_mod( 'column_1_category'); ),
'posts_per_page' => 2
);
I have already defined the column_1_category in customizer.php, and it works great by itself, but I would like whatever category is typed into the customizer to define the category_name in the $args = array( code.
The 'category_name' = > echo . . is the line that keeps giving me errors. I am assume, if this even works, that I am missing some code in there?
I was hoping this would be a quick and easy way to define the Category, but not sure if this would even work?
Thanks.
Nevermind, i figured it out. All I needed to do was:
$category_2_name = get_theme_mod( 'column_2_content');
$args = array(
'category_name' => ($category_2_name),
'posts_per_page' => 2
);

Count published sticky posts on Wordpress

I would like to get the number of published sticky posts on Wordpress. I can retrieve the number of sticky posts with
$sticky = count(get_option('sticky_posts'));
but it includes the planned posts, I don't want to include them
You can use WP_Query to filter these posts.
$args = [
'post__in' => get_option('sticky_posts'),
'post_status' => 'publish'
];
$posts = new WP_Query($args);
var_dump( $posts->posts );

WordPress: Taxonomy archives based on Custom Post Type

I've generated three different custom post types (e.g. books, movies, games).
And I've a custom taxonomy for all of them (e.g. genre).
What I need are archives for the taxanomy based on the post types.
For example: "books-genre", "movies-genre"...
Is there any solution to do that? Now I've only the taxonomy archive for "genre".
The way I like to approach custom post archives is to create a custom archive template with WP_Query sections where I need them. You'd create the blank file in the root of your theme at archive-cptnamehere.php.
You might have some template partials to add in but the core of the page looks like this:
<?php
// 1- Get ID of the page's path by URL (reliable)
$pagePath = $_SERVER['REQUEST_URI'];
$pageObject = get_page_by_path($pagePath);
$pagePathID = $pageObject->ID;
// 2- Print page title
$teamPageTitle = get_the_title($pagePathID);
echo $teamPageTitle;
// 3 - Do a query that gets the data you need
// Args: -1 shows all locations, orders locations alphabetically by title, orders locations a-z, only query against team items
$args = array(
'posts_per_page' => -1,
'orderby' => 'title',
'order' => 'ASC',
'post_type' => 'team',
'meta_query' => array(
array(
'key' => 'team_page_categorization',
'value' => $team_page_categorization_options_array_item,
'compare' => 'LIKE'
)
)
);
$the_query = new WP_Query( $args );
// 4- Setup query while loop
if($the_query->have_posts()) {
while($the_query->have_posts()) {
$the_query->the_post();
// 5- Do what you need to inside the loop
// 6- Close it all up, don't forget to reset_postdata so you can do additional queries if necessary!
}
wp_reset_postdata();
}
?>

How to display all posts of specific custom post types, including normal posts?

I want to display all posts of 2 specific custom post type (causes and evenements), but I also want to include all normal posts. Here's my query :
$args = array(
'post_type' => array( 'causes', 'evenements', 'post' ),
'posts_per_page' => -1,
);
$my_query = null;
$my_query = new WP_Query( $args );
Unfortunately, this only returns normal posts.
When I use this query, it shows all posts of causes and evenements custom posts :
$args = array(
'post_type' => array( 'causes', 'evenements' ),
'posts_per_page' => -1,
);
How can I display all posts of causes, evenements and post post types?
I can't use any value for the post_type because I also have other custom post types that I don't want to include in my query.
Thanks for the help!
Better to use this plugin Ultimate "Category Excluder"
It is simple to use and the ui provided is user friendly.

Resources