Trouble with paginating an archive page in wordpress - wordpress

Im trying to make an archive page in wordpress that works. Im trying to have the archive page show all posts in a list, but i dont want a list that is 100 list items long. So im trying to figure out how to get it to make a second, third, fourth, etc... page after about 20 to 30 list items on one page.
I dont mind using the wp-paginate plug in, but im still not sure how to get that to work with wp_get_archives()
I dont think it matters, but i will have a search bar on the page and its through google custom search. So i didnt supply it, as i dont think it contributes to the actual issue.
Any help would be greatly appreciated!
<?php
/*
Template Name: Archives
*/
get_header(); ?>
<div id="main">
<div id="posts">
<?php the_post(); ?>
<h1 class="entry-title"><?php the_title(); ?></h1>
<ul>
<?php wp_get_archives( 'type=postbypost' ); ?>
</ul>
<?php wp_link_pages(); ?>
<?php rewind_posts(); ?>
</div>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>

For pagination, I always use Eric Martin's emm_paginate function.
http://www.ericmmartin.com/pagination-function-for-wordpress/
In regards to your archive page, why not just use Wordpress's built in Archive page.
http://codex.wordpress.org/Creating_an_Archive_Index
With those two links, you should be able to build an Archive page that has the pagination you desire.

Related

Include Advanced Custom Fields (ACF) in Wordpress the_content()

I've inherited a project structure that uses front-page.php to render the home page. Most of the site uses the Wordpress content field, but we've switched to building new features with Advanced Custom Fields. the_content() is used throughout the codebase to render content, and I'm wondering if there is a way to include ACF layouts in the_content().
An example workaround I've had to use for the homepage is below, if I don't call the layout in this way content won't render on the page. I'm new to ACF, so if what I'm describing is a fundamental misunderstanding of how to bring ACF into an ecosystem I'd appreciate any guidance on better file structures and calling content.
<?php get_header(); ?>
<?php
if (is_page('Home')) {
?>
<div class="container">
<div class="row">
<?php
get_template_part('/layouts/home');
?>
</div>
</div>
<?php
} else {
the_content();
}
?>
<?php get_footer(); ?>
You can use ACF in addition to the original "the_content()" or "get_the_content()" functions. That content comes from the default block or WYSIWYG editor. ACF comes from additional fields that you add to your pages or posts.
<?php get_header(); ?>
<?php
if (is_page('Home')) {
$home_acf_field = get_field('field_name_from_home_acf');//this assumes that the ACF field has been added to the home page, because I'm not using the second parameter
?>
<div class="container">
<div class="row">
<?php
get_template_part('/layouts/home');
echo $home_acf_field;//this could also be placed in "layouts/home"
?>
</div>
</div>
<?php
} else {
$acf_field_from_page = get_field('field_name_from_page_acf');
the_content();
echo '<div>'.$acf_field_from_page.'</div>';//an example of where this can go
}
?>
<?php get_footer(); ?>
You can incorporate ACF in the template part, or in the page itself. You need to have the ACF field set up in the CMS to be on home or wherever, but then it's as simple as what I showed you to pull it in (my examples were assuming text fields).
You aren't asking this question, but if you are using "front-page.php" as your home page, then why do you need the if statements to show content? You can use "the_content()" in addition to your ACF fields, especially if it's the content editor from the home page. Or, you can just hide it (it's an ACF setting).
Note: I wrote this from memory, and didn't test anything, so please excuse any potential typo. :)

Wordpress showing post info under new pages, but I want it to show only under new posts

I have basic loop to show PHP posts
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<div class="post">
<h2><?php the_title(); ?></h2>
<div class="post-info"><?php echo get_the_date(); ?> - posted by <?php echo get_the_author(); ?> </a></div>
<?php the_content('<button class="show-more">Saznajte više</button>'); ?>
</div>
<?php
endwhile;
else :
echo "<p>No posts</p>";
endif;
It is the line that has <div class="post-info...
Now it is working very well, it shows date and author under post heading, but it also shows that when a new page is created. I understand Wordpress works like blog and it is natural for it to treat new pages as posts, however I want to avoid that behavior. I only want it to be shown under post headings, but not under new page headings. What would you suggest me?
https://developer.wordpress.org/themes/basics/template-hierarchy/
Check this template hierarchy and you'll understand how WordPress call template files.
Basically, WordPress firstly runs index.php and then call different template files. Since you only have index.php, so when rendering pages it all also falls back to index.php.
What you can do is creating a page.php with its own design for WordPress to call properly.

Wordpress - Post Page Associator Issues

For a client site that I am working on, the client wants to be able to associate certain custom post types to a given page. my supervisor has pointed me to the website of a previous client that did something similar. They used the Post Page Associator plugin (which seems to have been removed from the plugins list).
Here is a link to the plugin I am using: http://www.mediafire.com/?2dpbxac73rsn8l6
I've tried my best to modify the code inside the plugin to handle the custom post types I wanted to use (which the changes are included in the download). The main conflict comes from this piece of code (from the previous client's page.php file)
<?php
$sidebar = new WP_Query( $args ); //queries for posts
$sidebar = wp_plugin_post_page_associator::get_associated_posts ($post->ID); //looks for associated posts via the plugin, the main offending line of code
if ($sidebar!="") : while ( $sidebar->have_posts() ) : $sidebar->the_post();
?>
<div id="sidebar-content"> <!-- sidebar area -->
<h1 class="blue-text"><?php the_title(); ?></h1> <!-- the title of the associated post -->
<div class="divider"></div>
<?php the_content(); ?> <!-- the content of the associated post-->
<br/><br/>
</div>
<?php endwhile; else:?>
<br/><br/>
<?php endif; ?>
I was wondering if there was a way to determine what kind of post type the associated content is so I can change the WP_Query settings accordingly. If I comment out the second line of code with $sidebar, then all posts gets displayed in the sidebar. Is there a solution to this problem, or is there a better plugin for this?
I found a replacement plugin that does exactly what I need and shows me how to do it: http://www.cssigniter.com/ignite/custom-post-types-relationships/

Category Images Only Displaying Once on Special Recent Posts (WordPress)

I am using WordPress to put together a blog. I am using the Category Image(s) plugin to put an image for each category above the posts.
The main page is laid out as a big image and excerpt for each article and when you click on it, it takes you to the full article (I am using the 'Special Recent Posts' plugin for this). I want category image headers above each big image/excerpt.
Everything works fine for the first article but after that I get no headers. The reason is because the code I have in my header is calling the 'Category Image(s)' php function, which works. Then it calls the 'Special Recent Posts' php function which in effect runs the loop to grab the first five most recent articles. It doesn't run the category images function every time for every article, only the first time.
Here's the code:
<?php get_header(); ?>
<?php c2c_the_category_image($image_extensions='png gif jpg', $image_dir='/wp-content/images/', $use_name_if_no_image=true, $start_from='begin', $limit=999); ?>
<?php echo do_shortcode("[srp srp_number_post_option='5' srp_thumbnail_option='yes' srp_widget_title_hide_option='yes' srp_post_date_option='no' srp_wdg_excerpt_length='50' srp_wdg_excerpt_length_mode='fullexcerpt']"); ?>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
How can I get it to run the category images function for all the recent posts? Thanks for the help.
EDIT:
I attempting to go into the PHP of the Special Recent Posts plugin but when I attempted to enter the category images code in, it created some critical errors. I'm looking for the easiest solution if it's out there (I know this isn't a very simple question to start with). Any help? (I've placed a bounty)
Your way of doing things is extremely complicated and convoluted.
The simplest way that is proved to work is by having images that correspond with either category ID or category slug!
http://baldino.rs/collection
As you can see, this is a page that lists all the categories with their images and descriptions.
I'm having little trouble understading if you want:
To have a category image above every post
To have a category image AND post image above every post
I'll demonstrate the first solution below
Here is the order in which we will create the blog page:
Name the category images either by slug, or by ID (i recommend ID)
Upload the images to the server - prefferably to the images folder of the theme
Create our custom loop which will display our category image, category name, post title and excerpt
So the index page (blog page) should look something like this
<?php get_header();?>
<div id=:content">
<div id="posts">
<?php if (have_posts()) : while (have_posts()) : the_post();?>
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<?php
$category = get_the_category();?>
<img src="<?php bloginfo('template_directory'); ?>/images/<?php echo $category[0]->term_id;?>.jpg"/>
<h3 class="cat-title"><?php echo $category[0]->cat_name;?></h3>
<h2><?php the_title(); ?></h2>
<div class="entry">
<?php the_content(); ?>
</div>
</div>
<?php endwhile;endif; ?>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
You should really avoid plugins for the simple stuff that is easily solved by the loop
I recommend that you start reading the WP codex - http://codex.wordpress.org
Every function, class, reference is documented in detail and it's very easy to understand.
If you have more questions, do not hesitate to ask

Noob Question: Wordpress Looping

Can someone give me an essential Wordpress Loop and explain to me what's happening with it? I'd like to put together some templates, but I don't do well with blackboxing. In other words, I'm fully capable of writing my own CMS, but when it comes to using someone else's and its arbitrary rules, I'm completely at a loss, and I just can't get my head around the standard loop Wordpress uses. Thanks for your patient guidance.
There is a really nice tutorial from SpoonGraphics describing how to build your own theme for wordpress and explaining the required coding. It also covers the standard wordpress loop and explains how to build around it:
http://www.blog.spoongraphics.co.uk/tutorials/how-to-build-a-custom-wordpress-theme-from-scratch
You might want to start with reading the codex article on the The_Loop. Beyond reviewing their loop documentation, reading up on the various template tags should be helpful to you as well.
Begins the loop:
<?php if ( $posts ) : foreach ( $posts as $post ) : start_wp(); ?>
Generates a div container marked up with a post-specific id and post_class adds additionally CSS classes depending on the categories/tags/etc of the post.
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
Displays the post title as a permalink to the post.
<h2><?php the_title(); ?></h2
Displays some the post's publish date with a link to other posts by the same author.
<small><?php the_time('F jS, Y') ?> by <?php the_author_posts_link() ?></small>
Pulls the full contents of the post, wrapped in a div container to ease CSS styling.
Closes the loop, and displays a message if no posts were found.
<?php endforeach; else: ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

Resources