Hi I am trying to making my static wordpress page seen here
Link to the posts that are shown. However they are just linking to the file directory in the browser and not the post.
It was working before where it would just link to the post in a wordpress theme but now that doesn't even work.
I haven't touch the code in a week I left it in the state as mentioned above, where it would link but just to the wordpress theme.
Here is the code I use to get the information to the static page from wordpress -
<?php
// set up or arguments for our custom query
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'post',
'paged' => $paged
);
// create a new instance of WP_Query
$the_query = new WP_Query( $query_args );
?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); // run the loop ?>
<article>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content(); ?>
</div>
<small><?php the_time('F jS, Y'); ?> by <?php the_author_posts_link(); ?></small>
<hr>
</article>
<?php endwhile; ?>
<?php if ($the_query->max_num_pages > 1) { // check if the max number of pages is greater than 1 ?>
<nav class="prev-next-posts">
<div class="prev-posts-link">
<?php echo get_next_posts_link( 'Older Entries', $the_query->max_num_pages ); // display older posts link ?>
</div>
<div class="next-posts-link">
<?php echo get_previous_posts_link( 'Newer Entries' ); // display newer posts link ?>
</div>
</nav>
<?php } ?>
<?php else: ?>
<article>
<h1>Sorry...</h1>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
</article>
<?php endif; ?>
Basically what I am trying to do is get it so when I click on the post it takes me to that post. Not to the file directory.
Any help is appreciated. Thank you.
I'm using xubuntu 16.04_LTS incase that has anything to do with compatibility in wordpress.
I have permalinks setup as shown
If all you want is the links to work . . .
http://auroraservers.org/MainSite/?p=38 ---fails
http://auroraservers.org/MainSite/wordpress/?p=38 ---works
That works and could be adjusted in the permalinks custom area. If you want that URL to be different, you're dealing with htaccess changes.
While not beautiful, you could replace the_permalink(); with
$id = get_the_ID();
$url = 'http://auroraservers.org/MainSite/wordpress/?p='.$id;
try to rename Index.php as index.php. It seems like Wordpress can't find index.php as a template for the post and therefore the system redirects you to the file directory since it can't find any of the possible template files.
Addition: Since your "Index.php" seems not to include code for the display of single posts, you might want to set up a file "single.php" as a template for single posts. But nevertheless, Wordpress will try to use index.php in many situations - always when the actual template file for a particular post type can't be found, like archive.php, page.php and many others...
So it might be a good idea to create a "regular", all-purpose index.php, rename your static page to something else, for example to front-page.php and define t as your starting page.
I seem to have fixed the issue I have been having. Thanks for all the replies.
Incase someone needs to know what I have done.
I went into mysql and dropped the database and recreated it. Must of gotten corrupted somehow.
Related
I realized my website (www.inunfuturoaprile.it) with a minimal Wordpress theme that does not include the category.php template. I have created the template by me: the goal was to get pages that display a list of the posts belonging to a specific category. Unfortunately, due to my scarce knowledge of php, the code does not seem to work properly: I only see one post per category (e.g. https://www.inunfuturoaprile.it/politica/).
Here's the category.php file code:
<?php
/**
* Template di Categoria
*/
get_header(); ?>
<div id="content">
<?php
// Check if there are any posts to display
if ( have_posts() ) : ?>
<?php
// Since this template will only be used for Design category
// we can add category title and description manually.
// or even add images or change the layout
?>
<h1><strong><?php single_cat_title(); ?></strong>: Elenco Articoli</h1>
<div class="entry">
<?php
// The Loop
while ( have_posts() ) : the_post(); ?>
<?php the_title(); ?> // <small><?php the_time('j F Y') ?></small>
<?php endwhile; // End Loop
else: ?>
<h2 class="center">Not Found</h2>
<p class="center">Sorry, but you are looking for something that isn't here.</p>
<?php endif; ?>
</div>
</div>
<?php get_footer(); ?>
Someone can help me? Thank you :)
I think your posts_per_page parameter is set to 1.
You can see other posts using pagination:
https://www.inunfuturoaprile.it/politica/page/2/
https://www.inunfuturoaprile.it/politica/page/3/
Check it on Settings->Reading page ( /wp-admin/options-reading.php), parameter "Blog pages show at most"
But it also can be set up somewhere in the theme code.
Changing it may affect your main page - since the main page shows only one post too.
So you can change it only on category.php page. Add this after get_header():
get_header();
global $wp_query;
$wp_query->set('posts_per_page', 10);
// or this - if you need no pagination at all:
// $wp_query->set('nopaging', true);
$wp_query->query($wp_query->query_vars); ?>
I have been working on creating a custom loop and setting how many posts per page. I needed to make this loop separate to the blog posts per page - hence the custom loop.
Now the loop does work, however I noticed it is conflicting with the pagniation... pagination is showing but pages are not changing when you click 'next'.
Here is my loop:
<?php
$args = array('posts_per_page'=>12, 'post_type' =>'office');
$category_posts = new WP_Query($args);
if($category_posts->have_posts()) :
while($category_posts->have_posts()) :
$category_posts->the_post();
?>
<div class="office-item-wrapper">
<div class="office-item">
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
</article>
</div>
</div>
<?php endwhile; ?>
<?php else: ?>
<article>
<h2><?php _e( 'Sorry, nothing to display.', 'html5blank' ); ?></h2>
</article><!--/ Article -->
<?php endif; ?>
Thanks in advance to anyone who might be able to help me solve this issue :-)
In WP, the pagination is sent by a GET variable under page, just add it to the query args:
$page = get_query_var('paged');
$args = array('posts_per_page'=>12, 'post_type' =>'office', 'paged'=>$page);
I recommend you to use get_query_var('paged') because if it's empty it will be send you to the first page.
Note: In some themes, the page number is sent in the page key, so try with page or paged.
I have a site with a permalink structure I can't change, which is /blog/%category%/%postname%/ and I'm using previous_posts_link() and next_posts_link() to get pagination links. They work fine on date/all posts but not on category pages.
It's down to those links not having the right permalinks. They use /blog/events/page/2/ which results in a 404 page, whereas if I use /blog/category/events/page/2/, they work.
So, ideally I'd like /blog/events/page/2/ to work but if not then how can I get next_posts_link() to output the right links (/blog/category/events/page/2/)? Mindful of the fact I can't change the permalink structure, for seo purposes, apparently.
Here's the loop query:
<?php
global $query_string;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
parse_str( $query_string, $args );
$args['paged'] = $paged;
query_posts($args); ?>
<?php if (have_posts()) : ?>
<div id="post-results">
<div class="pagination">
<?php if (get_previous_posts_link()): ?>
<span><?php previous_posts_link( 'Recent posts' ); ?></span>
<?php endif; ?>
<?php if (get_next_posts_link()): ?>
<span><?php next_posts_link( 'Previous posts' ); ?></span>
<?php endif; ?>
</div>
... rest of loop
Thanks.
I had the same issue while working with plugin CPT UI custom post page template, and tried a lot to resolve the 404 page not found issue, Strangely the solution was quite simple, I just changes the permalink structure to "Numeric" and Voila it works!
Settings>>Permalinks>>Numeric
I have a single.php template but it shows all blogs posts. How do I prevent it from showing all posts:
Below is my code:
<?php $args = array('post_type' => 'realweddings');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();?>
<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h1 class="post-heading entry-title"><span class="left-hanger"><?php the_title(); ?> </span></h1>
<section class="overview">
<?php the_content(); ?>
</section>
<?php endif;?>
<?php comments_template(); ?>
</article>
<?php endwhile;?>
I think the correct question is, why am I using WP_Query to construct my loop in single.php. Frankly, I can't answer both.
Your problem is your custom query and the straight forward answer is, delete your custom query. You should never use a custom query in place of the main query. The main query is very specific on templates as it uses the URL to set the arguments in the main query, which is in fact also just a normal WP_Query
Just use the normal loop, that should fix your issue. A custom query is not the way to solve an issue with the main query
Pagination on my custom post page was working fine but after adding few posts it got broken - the older post link is not working any more.
Please suggest how can I fix it? I have tried disabling plugins, changing permalinks and almost anything i could find easy on the WordPress Codex.
Here's my query with pagination:
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array('post_type' => 'press' , 'posts_per_page' => 50 , 'paged' => $paged);
query_posts( $args );
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
//query_posts ( $args );//query_posts($query_string . '&caller_get_posts=6&posts_per_page=12');
?>
<ul class="griditemleft clear">
<?php if(have_posts()) : while(have_posts()) : the_post(); ?>
<?php if (has_post_thumbnail() ) : ?>
<li>
<?php the_post_thumbnail('category-thumbnail'); ?>
<h2 class="press-title"><?php the_title(); ?></h2>
</li>
<?php endif; ?>
<?php endwhile; ?>
</ul>
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Its not entirely clear on what you are trying to achieve, but I think you want to look closely at http://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination
Specifying hard-coded offsets in queries can and will break pagination since offset is used by WordPress internally to calculate and handle pagination.
To get around this limitation, you will need to write some additional code to manually handle pagination; you need to detect whether a loop has additional pages and then dynamically calculate the appropriate offset for the current page.
The code for controlling custom pagination will all occur within your functions.php file and not within the template page.php You can set an initial offset, as well as redefine the number of posts per page. There are specific samples displayed on the codex link above.
You will be adding the action before the query is run, via
add_action('pre_get_posts', 'myprefix_query_offset', 1 );
and you will have to account for the customization via
add_filter('found_posts', 'myprefix_adjust_offset_pagination', 1, 2 );