Wordpress permalink redirection - php

I am trying to create a theme for Wordpress where I have
0. landing page with static info and 6 latest posts. When user clicks on post title it is supposed to open it
1. all articles page with the same clickable function
What I've done so far
0. Pages index.php and page.php(this is the articles list page). In Wordpress settings those pages are added to "Pages" and page.php is child of index.php
1. This is my code in both files.
<?php
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<article class="post">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</article>
endwhile;
else :
echo '<p>No content found</p>';
endif;
?>
The problem:
It redirects me to the homepage again, just adding post ID to the link. The post IS actually displayed at the bottom of the page, but the previous content is still showing up (I mean, homepage is still there, just with the post at the bottom).
So, what may be wrong?
P.S. I don't have any active plugins and I have default .htaccess

Your problem is hard to understand, have you tried saving your Permalinks again and reproducing the problem in a private browser screen? (301 redirects get be cached as long as possible in your browser, so that might be a reason you (still) get redirected)

Related

how link several pages, and adding a plugin to a new custom WordPress theme

I've created my own WordPress custom theme for a website that I'm working on. It's my first time building a theme from scratch! I'm having a difficulty 1st: to link several pages to the fron-page, or home page. For example lets say that I want to link "Who we are", page + "Contact us", page, etc.. How can I make WordPress understands that each page is different, and link to it? here is what I did so far:
in page.php I placed this code:
<?php get_header(); ?>
<div class="container">
<?php
if (have_post()) {
while(have_post()) {
the_post();
get_template_part( 'template-parts/content', 'page');
}}
?>
</div>
<?php get_footer(); ?>
I also created a content-page.php where I've placed my HTML code. (I'm building the whole thing with an HTML and CSS code that's just like building a website from scratch).
I also want to know when using a plugin, how can I connect that into the pages that I'm adding. For example, if I'm installing a form such as WpForms for a page like "Contact us" how can I link that?
Please let me know if my questions need more details
If I understand this correctly...
You want to be able to display (link) a couple of pages to your home page?
Ex:
[home page content here]
[Connect page content here] [Blurb page here]
If so, you need to pull in the page content into the home page.
Something like:
<?php
$postid = 0 /*Need to get page id, that's the key */;
//Pull in the page data
$featured_page = get_post($postid);
$thumbnail = get_the_post_thumbnail( $featured_page->ID );
//Only show the excerpt in this case
$content = apply_filters( 'the_content', $featured_page->post_excerpt );
?>
<article id="post-<?php echo $featured_page->ID ?>">
<header class="entry-header">
<h1><?php echo $featured_page->post_title ?></h1>
</header>
<div class="entry-content">
<div class="thumbnail">
<?php echo $thumbnail; ?>
</div>
<div>
<?php echo $content; ?>
</div>
</div>
Important! You'll need to get the page id from somewhere. You can hard-code it in, but that's risky if something changes. You can set up an Customizer option that lets the user select what page to use.
https://codex.wordpress.org/Theme_Customization_API
As for the contact form etc. I'd suggest putting it on a page as a shortcode, then displaying the full page, not the excerpt.
I use this code for a theme I built myself. If you need anymore help, let me know, I can show you where to find it.

Adding content to wordpress page

So, i finally got my css and js scripts to load on WP
Now there is but one thing i need to get done.
i have my own theme, including header.php, footer.php, page.php
header.php and footer.php is working just fine, loading scripts and showing properly, but now i need to add all the other content.
my page.php is currently:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php the_content(); ?>
<?php get_footer(); ?>
I would need to somehow add html content to pages, i have about 20 ready made .php pages which needs to be transfered to WP.
Soooo how do i go about making new page (pages -> add new) and using page template while getting the html content to show up?
I've tried to just make new page and in text mode add up all the html into page, but it only shows empty page with header and footer, so the problem is most likely the page.php and i have no idea how to get it to work.
You can do look like this:
<?php /* Template Name: CustomPageT1 */ ?>
<?php get_header(); ?>
<?php
while ( have_posts() ) : the_post();
the_content();
endwhile;
?>
<?php get_footer(); ?>
You are on the good way. While developing a custom theme from scratch is a great challenge it's not too hard.
I could recommend to take it easy and follow this tutorial I found really helpful some time ago, I learned a lot there:
Developing a WordPress Theme from Scratch
You must have the official source documentation always in your mind:
Theme Development
Do some reading and you will see that making themes is really fun and gratifying :)
EDIT:
I would recommend picking a good starter theme or framework and work using child themes. You have plenty of them to pick.
To get started adding a new page to your WordPress site, find the Pages menu in the WordPress Dashboard Navigation menu. Click Add new.
The WordPress page editor looks nearly identical to the post editor, except for a few different boxes located on the right side of the screen.
Add the title of the page, like About. Note: If you have pretty permalinks set up, the title of your page will also be the URL slug.
Next, add some content.
The Publish section of the page editor is exactly the same as for writing posts. When you’re ready to publish, you can either publish immediately, save this or a draft, or schedule the page to be published later.
The Page Attributes section applies a parent page and template to your new page. For the Parent section, you can arrange your pages into hierarchies. For example, you could create this new page with additional pages under it. There are no limits to how many levels you can nest pages.
Some WordPress themes have custom page templates, so the next Template section allows you to apply a template to your new page.
The Order box allows you to order your page numerically. Pages are usually ordered alphabetically, but you can choose your own order by entering a number in this field.
Preview the page one last time, then click Publish. You’ve added a new page to your WordPress site.
This is how your
your index.php should look like :
<?php
get_header();?>
<div class="YourContainer">
<div class="Whatever">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="ContentSectionDiv">
<?php the_content();?>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php endif; ?>
</div>
</div>
<?php get_footer();?>
you can make also a custom loop
<?php
$arg = array("post_type" => "services",
"posts_per_page" => 9,
"order_by" => "date",
"order" => "ASC",
);
$services = new WP_Query($arg);
if ($services->have_posts()):;
while ($services->have_posts()):$services->the_post();
the_content();
endwhile;
endif;
?>

two separate blogs on one wordpress site

I did find one topic that sort of touched base on this but if there is a better link please advise.
I have a self hosted Wordpress website set up typically for a static home page and a separate page that shows recent posts called "Reviews". I need to write posts under a category "Recent News" that would be excluded from the recent post and shown on their own page, a second blog page.
The Codex tells me to add this to the index.php to exclude the category "recent-news":
<?php
if (is_home()) {
query_posts("cat=-3");
}
?>
with 3 being "recent-news". This does nothing no matter where I place it on the page. It still shows up with the recent posts. I'm guessing I'm in the wrong section for excluding categories in the Codex.
How do I exclude a category from recent posts, add a new page called "Recent News" and have it only show posts from the 'recent-news" category.
or have I climbed down a rabbit hole...
you can do it like this: edit your index.php page or create a custom template and then create a page (say "Front Page" ) and assign this template to it. In this template, copy your index.php code or if you feel confident simply create your template and include this code:
<?php if (have_posts()) : ?>
<?php $my_query=new WP_Query( 'cat=-3'); while
($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
<div class="post">
<h3><?php the_title(); ?></h3>
<?php the_content(); ?>
</div>
<?php endwhile;?>
<?php endif;?>
About your second question, simply go to Appearance --> Menu and there you'll see you can add pages but also categories. Simply select the category "Recent News" as a menu element and voilá, now you'll have a page displaying only posts from that category
I do not recommand messing with index.php
I think you should create a page template that will query posts from "Recent News" category.
Then in wordpress create a page and choose the page template you created.
In order to set it as the home page you will have to set it via wordpress configurations.
Wordpress page template
query posts by category
Set static homepage

Using the loop to display content, every page only displays Homepage

I am building a theme in WordPress and being a little out of practise I am struggling to make The Loop work properly. I have inserted the most basic loop into the theme and it displays the content fine.. but when I click onto another page or the news page etc, it still just displays the home page.
I'm not sure if I'm just being oblivious to some blindingly obvious problem with my code, but I assumed that the loop displayed whichever page you were currently viewing, or do I have to set up a mishmash of if(is_page('home')) then do a certain wp_query etc?
The loop code I have is inserted below, and if theres any information I forgot I will try update this post with it.
<?php query_posts(); ?>
<div class="content">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<h2><?php the_title() ;?></h2>
<?php the_content(); ?>
<?php endwhile; else: ?>
<p>Sorry, no posts to list</p>
<?php endif; ?>
</div>
Summary: The Loop is only displaying Homepage content on every page.
edit:
Even after disabling my plugin with the first loop in it, the proper Loop isn't working. it is the exact code posted above, and it just won't display the page I am on, or the news on the correct page or anything.... what am i missing
Try removing the query_posts(); line and try again
Apparently... My WordPress install doesn't work with pretty permalinks. As soon as I set it back to default settings, it all worked fine, but if I choose any option other than default, then only the homepage shows up (on any theme).

Wordpress use index.php instead of single.php to show post

My Wordpress websites are not using single.php to show posts on the website. Every time I open a post, it opens it in index.php.
My single.php looks like this
<?php get_header(); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<? echo the_content(); ?>
<? endwhile;
endif; ?>
<? get_footer();
?>
How can I fix this?
I had the same problem with neither the single-CUSTOM-TYPE.php nor the single.php being rendered after clicking the single-post-link.... only index.php instead of the correct file...
What helped me was a simple change back to Standard Permalinks in "Settings" -> "Permalinks" and a restore back to "Name of the Post" (Beitragsname)....
...maybe this might help someone else as well...
greetz
This happens if the LOOP is not correctly setup ensure that index.php, and single.php contains the LOOP.
The loop normally looks something like this, but will change to setup requirements.
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
The Wordpress Codex site is pretty awesome and will answer most questions, check out http://codex.wordpress.org/The_Loop
Furthermore questions and discussions such as this one is more ideal if you post on stacks sister site Wordpress Stackexchange. I expect this question will be deleted or moved to https://wordpress.stackexchange.com/.
You should check your loop.php or loop-single.php weather it is routing from these files or not this are the page from where it will bring the data from database

Categories