Skip to content

Instantly share code, notes, and snippets.

View rob-mathieu's full-sized avatar

Robbie Mathieu rob-mathieu

View GitHub Profile
@rob-mathieu
rob-mathieu / widget-recent-posts.php
Last active January 25, 2020 15:05
A customized recent posts widget for WordPress. Find the full tutorial for implementing the widget in my blog.
<?php
/**
* Widget for a Recent Posts
*/
// Register and load the widget
function load_custom_widget() {
register_widget('Custom_Recent_Posts_Widget');
}
// /components/pages/LocationsPage/index.js
import { useEffect, useState } from 'react';
import InfiniteScroll from 'react-infinite-scroller';
import { sortBy, uniqBy } from 'lodash';
import replaceall from 'replaceall';
import { useForm } from 'react-hook-form';
import { BiSearch } from 'react-icons/bi';
import { getLocations, setUserGeo } from '../../../lib/services';
// /lib/services/userGeo.js
// Set user lat/lng in localStorage
export const setUserGeo = async (userGeo) => {
if (typeof window !== 'undefined') {
await localStorage.setItem('userGeo', JSON.stringify(userGeo));
return true;
// /lib/services/index.js
import jwtDecode from 'jwt-decode';
import AuthService from '../services/auth'
import { wpgraph } from '../../api/wp';
import server from '../../api/server';
import { getUserGeo } from './userGeo';
const AUTH_URL = process.env.APP_AUTH_ENDPOINT;
const auth = new AuthService(AUTH_URL);
// /components/pages/LocationsPage/components/AutoSuggestInput.js
import Autosuggest from 'react-autosuggest';
import { FaMapPin } from 'react-icons/fa';
import { getAutocomplete } from '../../../../lib/services';
import Address from '../../../global/Address';
import TermIcon from '../../../../components/global/TermIcon';
// pages/locations/[country]/[state]/index.js
import { getLocations } from '../../../../lib/services';
import Layout from '../../../../components/layout/Layout';
import SeoHead from '../../../../components/global/SeoHead';
import StateDetailPage from '../../../../components/pages/StateDetailPage';
import { getAdventures, getLocationTypes, getStatePageBySlug, getStates } from '../../../../lib/services/wpQueries';
function State(props) {
const { page } = props;
// components/global/SeoHead/index.js
import { NextSeo } from 'next-seo';
import React, { Fragment } from 'react';
import { uniqBy } from 'lodash';
import Head from 'next/head';
import replaceall from 'replaceall';
import parse from 'html-react-parser';
import { removeTrailingSlash, replaceWithAppUrl } from '../../../lib/utils';
// components/layout/Layout.js
import { Fragment} from 'react';
import Header from './Header';
import Footer from './Footer';
const Layout = ({ children }) => {
return (
<Fragment>
<Header />
// components/pages/StateDetailPage/index.js
import { filter, map, remove, lowerCase } from 'lodash';
import PageMain from '../../../components/layout/PageMain';
import LocationsList from '../../../components/global/LocationsList';
import globals from '../../../lib/globals';
import PageHeader from '../../global/PageHeader/PageHeader';
import styles from './StateDetailPage.module.scss';
import Button from '../../global/buttons/Button';
import SectionAdventures from './components/SectionAdventures';
import { ButtonContainer } from '../../global/buttons';
// ======================================
// StateDetailPage
// ======================================
@import '../../../scss/utilities/_variables.scss';
@import '../../../scss/utilities/_mixins.scss';
.page-content {
flex-direction: column;
display: flex;