How to make a custom Archive page with Wordpress using custom post types and acf fields - wordpress-theming

I am building a child theme on GeneratePress to create a custom site for a client and am stuck on customizing the Archive pages. I've determined that it will be best to ignore the theme functionality and build the page loops from scratch. The custom archive should take the place of wp/generatepress' standard archive page and function in the same way by showing relevant posts when a taxonomy term is clicked. I need to be able to choose which html tags are used and style them with css. My issue is that I don't understand wordpress dev enough to figure out how to do this.
I have two custom post types, Research and Resources, as well as a bunch of different custom taxonomies that are applied to both or each post type. I'd like to customize the archive page (with archive templates if necessary) so it displays the appropriate Research and/or Resource files when visited.
I understand that I need to loop through all the posts, but I do not know how to grab only the relevant ones per the given archive page.
Examples of loops with example content will be the most helpful. Thank you!!

I chatted with someone on Reddit who kindly answered this question for me here.
They said:
So I wouldn't do it as a template personally (you could), I would do it through having two new files a archive-research.php & archive-resources.php.
Then if the loop is going to be the same on both pages, which I think you said it is going to be (you just want to display the posts from each custom post type), I would use a template part.
So create a new folder in your theme folder called inc or includes and name the file custom_post_loop.php (name can be anything).
Then in your archive page, call...
<?php get_template_part('inc/custom_post_loop');?>
In that file you are just wanting to write a simple post loop in there.
while ( have_posts() ) : the_post();
// Your loop code
// just so you can see this work I have called the title
the_title();
endwhile;
else : _e( 'Sorry, no posts were found.', 'textdomain' ); endif; ?>
https://developer.wordpress.org/reference/functions/have_posts/
Have a look at that link to find out more. But thats the direction to go...
If you really wanted to got the direction you have with the template, you would have to add arguments to your posts loop.
it works the same way but instead of archive.php its taxonomy.php...
However, you don't want a taxonomy-{taxonomy name}.php file for each taxonomy as that would be ridiculous unless you knew all the taxonomies haha and had really specific user cases for them...
so just create a taxonomy.php in your theme files and to make sure its working just add this code to it...
<?php get_header();>
<h1><?php the_archive_title();?></h1>
//then put your loop in from earlier...
<?php get_template_part('inc/custom_post_loop');?>
<?php get_footer();?>

Related

How can I add a new category to a morea site?

I'm trying to add a new 'project' category to a morea based site, where there will be a page similar to experiences page where I'll collect all course project related experiences and assignments, and maybe even modules.
Is it ok to look for pages with 'project' in their id or maybe better to tag with a new morea tag?
Do I need to also create a new entity type called 'project' or just reuse existing entities
In MoreaGeneraor.rb I couldn't find where module level page collections are prepared, like for example module_page.data['morea_experiences'].
I thought of preparing a similar collection of 'morea_project' pages and then traversing it in the new project page.
Is that done outside of this .rb file? by Jekyll? so how do I inject my collection.
Any simpler idea?...
Thank
p.s. I've also added the following (from line 3) to 'processMoreaFile()', but it does not seem to be visible at later stages:
elsif new_page.data['morea_type'] == "assessment"
site.config['morea_assessment_pages'] << new_page
if new_page.data['morea_id'].include?('project')
site.config['morea_project_pages'] << new_page
puts "--- project page #{new_page.data['morea_id']}\n "
end
but still do not know where to let each module page find out about it's 'project' pages
This is a cool idea. The simplest approach is to avoid making changes to MoreaGenerator.rb, and instead do it using normal Jekyll mechanisms. Here's a sketch:
Add a morea_label called "Project" to each associated module, reading, experience, and assessment.
In master/src, create a new directory called project, containing a file called index.md. This adds a new top-level page to your site (i.e. http://example.com/ics101/project/index.html)
Implement the index.md file with liquid tags to create the desired page layout for your project page. For inspiration, see the index.md files in the other top-level pages (readings, experiences, etc.). You can access YAML content in Liquid.
Once you've got your rocking project page done, you'll want a link to it in the navbar. See add a menu item for instructions.
Good luck! If you get it working to your satisfaction, please post its link as a followup to this question so we can see how it turned out!

Understanding wordpress the_content

I have been asked to tweak a friend's website. The website was built for them using Wordpress by an agency they no longer work with. Problem is, I don't know very much about Wordpress, so I have some basic questions…
I can see (by comparing the source as viewed in my browser to the php templates that I can edit through the Wordpress interface) that the elements I need to modify are generated by the page's call to "the_content()". I don't really understand what this function does, but I think it pulls content for a given page from the MySQL database. Is that right?
I suspect that the Wordpress interface alone won't be enough to let me modify elements that come out of that database. Is that correct? How does anyone change, for example, the specific arrangement of text and images on a page if the relevant markup is fetched by "get_content()"?
When developing for WordPress or even just tweaking, it's really important to get at least a general understanding of the "loop" and how we use it for output. In order to output the content you need to call the method within the loop. If it's not within the loop it won't get inserted into your page.
(It works this way with all of your pages... index.php, page.php, single.php, post.php, etc... Your methods need to be placed within the loop in order for them to display within that page.)
Here's a simple example of the way the loop is used to output the title and content of posts:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> // loop start
<h1><?php the_title() ;?></h1>
<?php the_content(); ?>
<?php endwhile; else: ?> // loop end
<p>Sorry, this page does not exist</p>
<?php endif; ?>
If you take a look at any standard WordPress theme (take Twenty Fourteen, for example), you'll find that the_content() is output together with calls to other elements (in this case - the_title()). If you want to want to change the arrangement of the specific elements within your page, just modify the order as they are within your loop, or check the WordPress Codex for additional options/methods.
Here's a short list of some other things you can display:
next_post_link – Displays a link to the post published chronologically after the current post.
previous_post_link – Displays a link to the post published chronologically before the
current post.
the_category – Displays the category or categories associated to the post or page being viewed.
the_author – Displays the author of the post or page.
the_content – Displays the main content for a post or page.
the_excerpt – Displays the first 55 words of a post’s main content then with a [...] or read more link that goes to the full post. The length of excerpts can be controlled by using this slightly advanced method or by using the Excerpt field on the post edit page.
the_ID – Displays the ID for the post or page.
the_meta – Used to display custom fields.
the_shortlink – Displays a link to the page or post using the url of the site using
the ID of the post or page.
the_tags – Displays the tag or tags associated with the post.
the_title – Displays the title of the post or page.
the_time – Displays the time or date for the post or page. This can be customized using the standard php date function formatting.
If you want to further customize some of these methods, you can do that within functions.php. Otherwise, all styling is done within your styles.css.
Probably your content is being generated by a shortcode.
You can modify the content that wordpress fetches from the database with the_content filter:
// returns the content of $GLOBALS['post']
// if the page is called 'debug'
function my_the_content_filter($content) {
// assuming you have created a page/post entitled 'debug'
if ($GLOBALS['post']->post_name == 'debug') {
return var_export($GLOBALS['post'], TRUE );
}
// otherwise returns the database content
return $content;
}
add_filter( 'the_content', 'my_the_content_filter' );
maybe its not the best solution but you can modify the content before it gets output.
source

WordPress Paradox - Normal posts not being queried

I am in a situation that i can't figure out. I am running a WP 3.4.2 on a site with multiple custom post types. The normal posts are displayed in the blog section and are in a category called blog with different subcategories.
Blog posts and another post type called 'events' display tags in single view. The tags display fine but when you click on a blog post tag no posts are found. Tags related to events work as expected.
The really weird thing is in admin. when I search a tag that is related to a normal post, it finds it and counts how many posts it has, but when clicking on the number of posts is says "No posts found.". With the tags related to events this never happens.
Also, categories have the same problem.. display just posts from events..
Also I tried to make another post type called "blogposts" to display on the blog page instead of normal posts but same sad story.
As far as I see in the code, in archive.php and tag.php, normal posts are not returned from the query, just events get through.
I have this in functions.php
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array('post', 'events', 'blogposts' ));
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types' );
Any ideas would be really welcomed.
Thanks!
This is a weird problem. Most likely caused by a combination of plugin(s) and/or theme.
So first we need to figure out where the problem comes from. So:
turn off all plugins to see if it changes.
Or do it one by one
turn off parts in functions.php in your theme.
turn as many off as possible and see if things change
To find this problem we need more specific information.
Is it your won theme or someone else's?
What plugins are active?
Is this problem new, or did it just 'popup'?
good luck and let me know what you find ;)

Using multiple layout in Yii

My Yii application has a particular section called 'Edit Profile' . It's a pretty data heavy section in the way a lot of data is pulled from db for this one .
However the problem is that I have tab pagination in this section . Because only this section uses tabs on the website I did not include the related CSS/Javascript files in the main layout header .These have been referenced in the view file itself . Because of this the tabs takes time to show up and the tab titles appear as a list first (for a second or two) and then get distributed into tabs with the correct UI . This is of course unacceptable behaviour . Is there any way to selectively include related js/css files into the header tag for this particular view or should I include it in main layhout file even though it won't be used in a lot of other places on the website thus possibly slowing down other pages .
Just specify the position for the file.
In your view where you are including the js or css :
// for js
Yii::app()->clientScript->registerScriptFile('url_of_file',CClientScript::POS_HEAD);
// for css
Yii::app()->clientScript->registerCssFile('url_of_file');
Recommended documentation: registerScriptFile() , and registerCssFile()
You can create your own layout in the layouts folder , where u can include all the required jquery scripts and css. U can then call your layout in the controller.
public function actionDoSomething(){
$this->layout = 'mylayout';
$this->render('myview');
}

Wrap MediaWiki in another website

I want to wrap a mediawiki site inside another site - using the header.inc and footer.inc files that the rest of the website's html files use.
I'm not familiar with php, is there a 'masterpage' file somewhere I can put them in?
Your best bet would be to create a custom skin, or edit one of the default skins, such as monobook. They control most of the basic presentation code. Here is one short tutorial on creating a custom skin. The files usually live in the /skins/ folder; if you skim through one, you can find where the HTML begins and ends.
You can include another file using the PHP include function, like so:
<html>
...
<body>
<?php
include 'header.inc';
?>
...
For future reference in the LocalSettings.php you can also prevent users from using any other skin.
$wgDefaultSkin = 'myskin';
$wgAllowUserSkin = false;
$wgSkipSkins = array( "chick", "cologneblue", "monobook", "modern", "myskin", "nostalgia", "simple", "standard" );